[Libwebsockets] controlled client initated close

Otto Moerbeek otto at drijf.net
Fri Dec 15 16:35:36 CET 2017

On Mon, Dec 11, 2017 at 11:36:29AM +0100, Otto Moerbeek wrote:

> 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?

To reply to myself ith some more info:

I managed to do a proper client-initialed shutdown using

	lws_write(..., 4);

This is of course against the API, but as said, using
lws_close_reason() does not works for me with both libwebsockets 2.3.0
and 2.4.1.


More information about the Libwebsockets mailing list