[Libwebsockets] multiple clients

Andy Green andy at warmcat.com
Fri Apr 7 01:08:08 CEST 2017



On April 7, 2017 6:58:53 AM GMT+08:00, Joel Winarske <joel.winarske at gmail.com> wrote:
>Multiple http client instances via lws_client_connect_via_info().
>
>Where can I find a good example of using the "user" pointer in
>callbacks?

If you're being the server, eg

https://github.com/warmcat/libwebsockets/blob/master/plugins/protocol_dumb_increment.c

Client is the same way... set the size of the user allocation in the protocols[] struct and then cast user to a per-client 'pss' struct.  Each wsi gets his own private pss for as long as he is associated with the protocol.

-Andy

>
>On Thu, Apr 6, 2017 at 3:43 PM, Andy Green <andy at warmcat.com> wrote:
>
>>
>>
>> On April 7, 2017 2:46:44 AM GMT+08:00, Joel Winarske <
>> joel.winarske at gmail.com> wrote:
>> >Hi Andy,
>> >
>> >Is there anything preventing simultaneous http clients, or can there
>> >only
>> >be one at a time?
>>
>> What does 'clients' mean here?  You are being the server and the
>clients
>> are remote guys connecting to you?  Or they are your outgoing
>connections?
>> Either way:
>>
>> No, you can have as many clients as you have sockets available.
>>
>> >In my case I'm seeing two stomp on each other, but I'm figuring it's
>my
>> >code; thought I would ask!
>>
>> They won't 'stomp on each other' (no better characterization also
>suggests
>> it's user code) in lws.  But your user code has to be appropriate, if
>you
>> point all clients at the same filescope static vars, naturally you
>will
>> have problems with vars being overwritten.  Look at how the plugin
>type
>> code manages a vhd for the vhost and a pss per connection.
>>
>> -Andy
>>
>> >
>> >Thanks,
>> >Joel
>>



More information about the Libwebsockets mailing list