[Libwebsockets] client connect in lwsws

Andy Green andy at warmcat.com
Sun Feb 12 02:14:20 CET 2017



On 12 February 2017 07:21:55 GMT+08:00, Joel Winarske <joel.winarske at gmail.com> wrote:
>Hi Andy,
>
>I want to client connect to https site from within
>LWS_CALLBACK_HTTP_BODY_COMPLETION, in a running instance of lwsws. 
>lwsws
>is running in non-SSL
>
>Due to SSL, I was figuring lws_client_connect_via_info(), similar to

Yes this is the way.

>test-client.c.  I'm not clear where context and wsi should come from in
>the
>case of running within lwsws.

All wsi are under the same context, and a context may mix client and server wsi ok.

So you can get the context from the callback wsi with lws_get_context(wsi).

When you call lws_client_connect_via_info(), he will try to start the logical client connection process and return either a new wsi representing the client connection if it got started, or NULL if it failed.  However because the connection attempt may generate callbacks before lws_client_connect_via_info() returned and told you the new wsi, the info struct also contains a *pwsi member that lws_client_connect_via_info() sets to the new wsi before it returns.

In that way you can recognize in the callback who the wsi is, even during these early callbackS.  That's particularly useful if the connection fails, since you get a callback with a descriptive reason string, beimg able to know that's your wsi failed lets you respond to it.

>I figure it would get serviced by the server loop, so no need to
>call lws_service().  Correct?

Yeah no need for that, lwsws context is using libuv event loop, when you make the client connection it joins in with that.

Notice in lwsws you must mark a vhost as wanting to / being able to make ssl client connections

 - "enable-client-ssl": "1" enables the vhost's client SSL context, you will need this if you plan to create client conections on the vhost that will use SSL. You don't need it if you only want http / ws client connections.

This causes the vhost to additionally init client ssl context.

-Andy

>Thanks,
>Joel

-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.



More information about the Libwebsockets mailing list