[Libwebsockets] A question about close frame ctroll for ws client in libwebsockets
andy at warmcat.com
Fri Mar 13 06:35:47 CET 2020
On 3/13/20 4:24 AM, huangkaicheng wrote:
> We use libwebsockets as ws client. We want to know that how to
> get the reason code and descption if ws server send close frame with
> close_staus and buffer . We found the interface “lws_close_reason” about
> send to close frame in libwebsocket.h
> but we does not found how to get reason when ws client receive
> close frame.
> as ws client ,how to get close status and buf? Can callback reason
> about “LWS_CALLBACK_CLOSED” get close status ? if not, how to get it.
> Please help answer for me. Thanks.
You should get a LWS_CALLBACK_WS_PEER_INITIATED_CLOSE callback if the
peer sent the CLOSE frame and we received it
... but CLOSE frames are pretty unreliable... if anything acted to stop
the tcp link passing traffic, or broke the tls tunnel, or there was a
protocol violation at ws layer, or you wanted to close but you're in the
middle of a long data frame, all of these mean you won't be able to
transfer another control frame, and the connection is just ended
suddenly. So while it's OK to handle them it's not a good idea to
assume you will get one.
More information about the Libwebsockets