[Libwebsockets] controlled client initated close

Otto Moerbeek otto at drijf.net
Mon Dec 11 11:36:29 CET 2017


Hi,

I have a websocket that is operating properly, but I would like to
close the websocket in a proper way if the client is about to quit.

So what I'm doing in the client is:

lws_close_reason(wsi, LWS_CLOSE_STATUS_GOINGAWAY, NULL, 0); 
return -1 from the user callback on LWS_CALLBACK_CLIENT_WRITEABLE.

That indeed initates a close, but it seems to be a hard TCP socket
close; the server sees:

CloseReason: code [1006], reason [null]

1006 is LWS_CLOSE_STATUS_ABNORMAL_CLOSE, so the client is not doing a
controlled close.

Am I doing something wrong here? What is the proper way to initate a 
websocket close by a client?

Regards,

	-Otto


More information about the Libwebsockets mailing list