[Libwebsockets] Close event

Andy Green andy at warmcat.com
Thu Dec 6 17:04:15 CET 2018

On December 6, 2018 10:28:06 PM GMT+08:00, Stefano Mora <stefano.mora at newdep.com> wrote:
>Hi everyone,
>I'm using the library to write a ws server and I'm very happy of it; it
>is working very well.
>The only problem is that 'sometimes' a unexpected CLOSE event is
>received by the server but it is not sent from the (only) client.

The CLOSE callback just means the connection is closed, it doesn't always imply "...received by the server..."".  There are many reasons the server might decide to terminate the connection itself.  For example lws may enforce timeouts, or if you told it to check, receiving invalid utf-8 in a ws TEXT message will cause the server to hang up on you


Protocol violations in the tls wrapper will cause the tls library to hang up the connection and lws will just tell you it closed; it's just reporting what it observed.

The lws logs contain information about where in lws the close happened and a reason code that might help.  Build lws with -DCMAKE_BUILD_TYPE=DEBUG and run with -d 1039 to enable INFO logging as well as the usual.  Then wait for the problem and find the related logs.


>I'm wondering if I can understand the reason of this CLOSE event and,
>if not requested, how can avoid it.
>Stefano Mora / SW Engineer
>stefano.mora at newdep.com<mailto:stefano.mora at newdep.com>
>Office: +39 0521 1756850/ Fax: +39 0521 1800611
>Via Emilio Lepido 55/A - 43123 Parma - ITALY
>Web site: www.newdep.com<http://www.newdep.com/>
>Il presente messaggio, corredato dei relativi allegati, contiene
>informazioni strettamente riservate ai sensi del D.L.gs. 196/2003 ed è
>destinato esclusivamente ai destinatari. Chiunque ricevesse questo
>messaggio per errore è pregato di darne gentilmente comunicazione al
>mittente, di non copiarlo, divulgarlo o distribuirlo, nonchè di
>This communication may contain confidential and/or otherwise
>proprietary material and is thus for use only by the intended
>recipient. If you received this in error, please contact the sender and
>delete the e-mail and its attachments from all computers.

More information about the Libwebsockets mailing list