Page 1 of 1

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

Posted: Wed Nov 17, 2021 8:23 am
by lukecam95
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

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

Posted: Thu Nov 18, 2021 9:40 am
by ESP_YJM
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.

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

Posted: Fri Nov 19, 2021 12:57 pm
by lukecam95
Thanks that did the trick :)

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

Posted: Sun Jan 29, 2023 9:07 am
by w4d4f4k
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.

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

Posted: Fri Feb 03, 2023 11:39 am
by w4d4f4k
so yes it works with xtaskcreate and to save socket somewhere..