[Libwebsockets] Multiple Connections on vhosts

Derek Bailey dbaileychess at gmail.com
Thu Aug 30 19:13:15 CEST 2018


I understand there is one 'context' that can have multiple 'vhosts' (given
the LWS_SERVER_OPTION_EXPLICIT_VHOSTS option is set), which can have
multiple protocols. And these 'vhosts' are created using the
'lws_create_vhost' function in the same thread running the 'lws_service'

I am curious on how to properly perform a new client connection
('lws_client_connect_via_info') in one of these vhosts, from an external
thread. In the minified client example:


The 'default' vhost is created automatically and the
'LWS_CALLBACK_PROTOCOL_INIT' callback is handled and that is where the
connection first occurs. When I tried to adapt the code to allow multiple
distinct connections to be initiated externally, I naively create new
'vhosts' for each connection, and used the same calllback to init. But if a
vhost can support multiple client connections (with different endpoints)
what is the best way to do it from an external thread? Do i have serialize
this step in the main service thread and call 'lws_cancel_service' to
trigger it?

I think the examples are great! It would be nice to have one that shows how
multiple clients can be created in the same process, using the same
context. All the examples that I saw for clients assume a single client.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://libwebsockets.org/pipermail/libwebsockets/attachments/20180830/b5ca01c4/attachment.html>

More information about the Libwebsockets mailing list