4.3 server websocket - send_frame delayed when using async_send
Posted: Sun Aug 23, 2020 1:20 am
Is this normal behavior? Chrome client is connected to the ESP's httpd server through a websocket.
When I receive a packet on the ESP, if I only respond with httpd_ws_send_frame() the browser receives the reply immediately. But if I send a response then trigger an async send like in the example, the client receives both packets at the same time. Like the first packet is delayed until the work function has been called, even if the work function takes several seconds to execute. If I insert a small 20ms delay between httpd_ws_send_frame() and the trigger_async_send() then I correctly receive the first message before the second but it's flaky and doesn't seem reliable, beside being ugly. I don't want to insert delays everywhere.
I tried sending the response before and after calling trigger_async send. I set the httpd server priority to 3. I tried setting the TCP_NODELAY socket option and so far nothing works although I'm not entirely sure I'm setting the TCP_NODELAY option correctly even if setsockopt() returns 0. As soon as I do both send a response and trigger an async send, the first response is delayed.
Any thoughts? I'm thinking of just using multiple async_send when I have to send data more than once for a single request and use the httpd_ws_send_frame() 'normal reply' only when I have to send data only once for a request. But I would prefer to do what seems logic, i.e. sending a response to a request and then asynchronously sending the remainder of the response when it's ready.
When I receive a packet on the ESP, if I only respond with httpd_ws_send_frame() the browser receives the reply immediately. But if I send a response then trigger an async send like in the example, the client receives both packets at the same time. Like the first packet is delayed until the work function has been called, even if the work function takes several seconds to execute. If I insert a small 20ms delay between httpd_ws_send_frame() and the trigger_async_send() then I correctly receive the first message before the second but it's flaky and doesn't seem reliable, beside being ugly. I don't want to insert delays everywhere.
I tried sending the response before and after calling trigger_async send. I set the httpd server priority to 3. I tried setting the TCP_NODELAY socket option and so far nothing works although I'm not entirely sure I'm setting the TCP_NODELAY option correctly even if setsockopt() returns 0. As soon as I do both send a response and trigger an async send, the first response is delayed.
Any thoughts? I'm thinking of just using multiple async_send when I have to send data more than once for a single request and use the httpd_ws_send_frame() 'normal reply' only when I have to send data only once for a request. But I would prefer to do what seems logic, i.e. sending a response to a request and then asynchronously sending the remainder of the response when it's ready.