[Libwebsockets] Client close example

Andy Green andy at warmcat.com
Wed Apr 26 00:11:46 CEST 2017

On April 26, 2017 6:02:25 AM GMT+08:00, Brenton Rothchild <brentonr at dorm.org> wrote:
>I've tried looking for examples on this list or in documentation, but
>far I cannot find a good answer to the following question:
>Can someone give a good example (simple, single threaded) where the
>sends a closing
>reason to a WS server (any kind) with a reason using
>I am finding that with v2.1.0 and v2.2.1, I get sporadic results where
>sometimes callling lws_close_reason() and returning -1 from the
>will not actually send the close message payload and the socket is
>closed (as viewed using tcpdump).
>I'm fairly positive I'm simply not using the library correctly, and
>very much appreciate a
>concrete example where the client is closing the connection with a

Run libwebsockets-test-server, visit http://localhost:7681, go to the 'close testing' tab and use the open and close buttons there.  The sources are in ./test-server.

There are no guarantees the peer hasn't already closed the tcp connection, and it's legal for either side to close the connection with no warning at any time.

If there's a gap in the close logic under some circumstances, you'll need to capture more info on how to reproduce.



More information about the Libwebsockets mailing list