[Libwebsockets] Is there a way to reuse a lws_context without destroying it

Andy Green andy at warmcat.com
Thu Jun 15 00:36:03 CEST 2017

On June 15, 2017 1:29:46 AM GMT+08:00, Ash 20001 <ash20001 at hotmail.com> wrote:
>sorry i forgot to mention that on reconnect i am connecting to a
>different port and potentially even different server ip. Is that why it
>won't work with the same context?

Doubt it, every connect starts fresh.

>From: Ash 20001 <ash20001 at hotmail.com>
>Sent: Wednesday, June 14, 2017 8:47 AM
>To: Andy Green
>Subject: Re: [Libwebsockets] Is there a way to reuse a lws_context
>without destroying it
>I am using 1.7 websockets. When I try it again, I start immediately

1.7 is too old... please see if you still have a problem on master lws.

>getting callback_closed messages after lws_client_connect_via_info is
>called. I have no idea why I am getting these messages but if I destroy
>the context and then call lws_Create_Context again, it works.

In later lws in CONNECTION_ERROR, *in may point to a string describing the problem.

>In libwebsockets-test-client, it doesn't seem to handle callback closed
>or callback connection error. Normally during these events I exit out

It does handle them, or it doesn't know it should retry (mymemory only goesback to v2.0-ish though).

>of the main lws_Service loop, and then later I try to call
>connect_via_info again, restart the service loop, and then run into the
>issue above. What should I do to prevent this?

See if it still happens on later lws.

>Yes openssl is being trashed and messing around with other threads
>using curl to an https source for instance so I am trying to workaround
>it because I cannot change the openssl version.

You're going to have to change something...


>From: Andy Green <andy at warmcat.com>
>Sent: Wednesday, June 14, 2017 12:29 AM
>To: libwebsockets at ml.libwebsockets.org; Ash 20001;
>libwebsockets at ml.libwebsockets.org
>Subject: Re: [Libwebsockets] Is there a way to reuse a lws_context
>without destroying it
>On June 14, 2017 2:35:24 PM GMT+08:00, Ash 20001 <ash20001 at hotmail.com>
>>Is there a way to call lws_create_context just once for program
>>lifetime as a client, and use that context for many connections (ie.
>>connect to a server, disconnect, repeat)? I have tried but it doesn't
>>seem to work on the second connection.
>Yes it should be fine.
>Libwebsockets-test-client does exactly this in its normal operation.
>What exactly happens (and does it happen on lws master?)
>>The reason I ask is because I am having SSL issues with other threads
>>that I have no control over in a process which use ssl functions in
>>CURL. lws_destroy_context globally destructs SSL state and causes
>>issues.  My openssl version is rather old 0.9.8 and cannot be changed.
>Yeah.... we have seen it before.  Later openssl fixed it.
>It will trash openssl for the whole process.  Is that why you can't get
>a second client connection in lws?
>>(Sorry if I sent two emails, not sure if the first one went through
>>because I was trying to subscribe to the mailing list).

More information about the Libwebsockets mailing list