How to write a websocket server without receive any packet from client after handshake

aurosoares
Posts: 4
Joined: Thu Sep 21, 2023 2:51 pm

How to write a websocket server without receive any packet from client after handshake

Postby aurosoares » Thu Sep 21, 2023 3:21 pm

I'm writing a websocket server based on the github example "echo websocket"(https://github.com/espressif/esp-idf/tr ... cho_server).

The client always receives packets after sending a message to the server in that implementation, however, is there any way to implement a websocket server that periodically sends some data without needing to receive any messages ?

I want just connecting my client and starting to receive data periodically without sending messages.

Auro.

vinci1989
Posts: 28
Joined: Mon Oct 08, 2018 6:07 pm

Re: How to write a websocket server without receive any packet from client after handshake

Postby vinci1989 » Fri Sep 22, 2023 8:25 am

A websocket is a bidirectional communication. As long as the socket is open you can send data at any time. The example you've linked even does that by using the

Code: Select all

ws_async_send
function.

aurosoares
Posts: 4
Joined: Thu Sep 21, 2023 2:51 pm

Re: How to write a websocket server without receive any packet from client after handshake

Postby aurosoares » Fri Sep 22, 2023 3:14 pm

Thank you for response.

I changed the implementation to an infinite loop within the websocket's http handler, to keep sending the packets. Like a default tcp server. Its works fine, but during the loop execution, all other http requests that are on my server are not answered.

Is there any way to send packets periodically without blocking new http calls during this process?

Who is online

Users browsing this forum: Baidu [Spider], Majestic-12 [Bot] and 84 guests