[Libwebsockets] Client App | Recreating websocket connection faster

Andy Green andy at warmcat.com
Sat Jul 16 13:23:04 CEST 2016

On July 16, 2016 7:03:54 PM GMT+08:00, Harshad Italiya <harshaditaliya at gmail.com> wrote:
>I am using libwebsocket and I have created client application. I am
>GSM modem in my system for internet connectivity and because of that
>are many times I am loosing GPRS and I have implemented my application
>such a way so if there is GPRS lost then I am closing the connection
>by *"lws_context_destroy(lws_context)"

No... that destroys the whole context.

You'd do that when your app was closing.

>*this can also be in case when there is something wrong between client
>server custom protocol communication missing.
>I have seen when I am closing connection when GPRS is lost and then
>back but not able to create a connection with server. While if I
>application then it gets connect fine.
>Is wait required after *lws_context_destroy* function call and before
>calling *lws_client_connect function*.

No... closing a connection is a different animal.

create context {

  connect and close connections as many times as you like

} destroy context
exit program

There are two valid ways to close client connections... return nonzero from most callbacks, or set the timeout on the wsi to, eg, -1.

More importantly look at the test client in ./test-server/test-client.c and follow how that works, if you did that you would see destroying the context happens when it exits, although it closes and creates connections many times (eg mirror connections last for a random 'lifetime' and then reconnect).


>Libwebsockets mailing list
>Libwebsockets at ml.libwebsockets.org

More information about the Libwebsockets mailing list