Web socket - Send asynchronous message from server to client without request from client

lukecam95
Posts: 14
Joined: Thu Sep 23, 2021 9:37 am

Web socket - Send asynchronous message from server to client without request from client

Postby lukecam95 » Wed Nov 17, 2021 8:23 am

Hi,

In the esp-idf included example ws_echo_server.c I cannot understand how the server can send a message to the client without the client sending a request previously. The function

Code: Select all

trigger_async_send(httpd_handle_t handle, httpd_req_t *req)
requires the client to send a request first. Also, the function:

Code: Select all

 httpd_ws_send_frame(httpd_req_t *req, httpd_ws_frame_t *pkt)
requires a existing request to be received so I cannot just send a packet.

Can somebody please clear this up please.

Regards,
Luke

ESP_YJM
Posts: 300
Joined: Fri Feb 26, 2021 10:30 am

Re: Web socket - Send asynchronous message from server to client without request from client

Postby ESP_YJM » Thu Nov 18, 2021 9:40 am

You can use API

Code: Select all

esp_err_t httpd_ws_send_frame_async(httpd_handle_t hd, int fd, httpd_ws_frame_t *frame);
For this API, you need record the fd in the previous connection.

lukecam95
Posts: 14
Joined: Thu Sep 23, 2021 9:37 am

Re: Web socket - Send asynchronous message from server to client without request from client

Postby lukecam95 » Fri Nov 19, 2021 12:57 pm

Thanks that did the trick :)

w4d4f4k
Posts: 27
Joined: Fri Dec 02, 2022 10:41 pm

Re: Web socket - Send asynchronous message from server to client without request from client

Postby w4d4f4k » Sun Jan 29, 2023 9:07 am

but if we run this in loop then user can not send no more requests.. is possible to increase number of connections for client..? maybe to run with xTaskCreate.. will try and noticing.

w4d4f4k
Posts: 27
Joined: Fri Dec 02, 2022 10:41 pm

Re: Web socket - Send asynchronous message from server to client without request from client

Postby w4d4f4k » Fri Feb 03, 2023 11:39 am

so yes it works with xtaskcreate and to save socket somewhere..

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 102 guests