[Libwebsockets] Sending WS Connection Close packet immediately from the lws client

Mateusz Stępień mateusz.stepien at netrounds.com
Tue May 21 15:17:16 CEST 2019


On 5/21/19 2:51 PM, Andy Green wrote:
 > There's also this api
 >
 > 
https://libwebsockets.org/git/libwebsockets/tree/include/libwebsockets/lws-timeout-timer.h#n79-105

That function would probably help, when I could get to the point that 
Close message is already sent and I'm waiting for ACK from the server.

> You can never guarantee you can either send the close frame at all or 
> when you can send it.

That can be said about every packet going out from the client. However 
the issue is not about flaky connection or sth like that. It is that 
that I cannot send Close message like I can send any other one. Right 
now if I want to close the connection with a close message and a chosen 
reason, I need to wait for the CLIENT_RECEIVE callback and because I 
cannot force it, I am at the mercy of server, which can send another 
message in 5 seconds, or in 20 minutes, or never. Please note, that I'm 
talking about time between setting "completed" flag and receiving 
CLIENT_RECEIVE callback.

> If it can be sent within a timeout period of a 
> few seconds, it will be sent.  But anything can crash or run out of 
> battery or lose connection at any time without ceremony.  So you 
> shouldn't assume this can be made a certainty... CLOSE callback to learn 
> the socket closed is much more certain.

I'm sorry, but I don't see the relevance to my issue. At the CLOSE 
callback there's nothing I can do to send the Close message.


More information about the Libwebsockets mailing list