[Libwebsockets] Multiple http ports.

Andy Green andy at warmcat.com
Wed Jul 23 03:36:11 CEST 2014



On 23 July 2014 08:03:57 GMT+08:00, Steve Calfee <scalfee at mqidentity.com> wrote:
>Hi, has anyone done a slightly more complex server, where more than on
>server instance is started on more than one port? For instance an app
>that wanted to serve two different pages on two different ports. I
>guess I could do a similar thing by taking a path in the url to
>indicate which  page.

Yes others are running eg as many instances as they have cpu cores.

If you just want two pages, you're better off serving a different page based on the url requested.  The test server just has a very minimal url space but even so shows how to fo it for leaf.jpg.

>I can create multiple contexts, but then the serving breaks. I do call
>each context with libwebsocket_service(context, timer); Some of the api

It is actually okay but read below.

>seems to disallow multiple servers, because they don't take a server
>context such as:
>
>libwebsocket_callback_on_writable_all_protocol(&protocols[PROTOCOL_DUMB_INCREMENT])
>
>If I could do multiple ports what would the above call do?

There is no problem because the protocols struct contains a pointer to the context that was set when the context was created.

In turn though it means you can't share one protocols struct between multiple contexts, you need an individual struct protocols (perhaps memcpy'd from a template) for each context you create.

-Andy

>Thanks.
>_______________________________________________
>Libwebsockets mailing list
>Libwebsockets at ml.libwebsockets.org
>http://ml.libwebsockets.org/mailman/listinfo/libwebsockets




More information about the Libwebsockets mailing list