[Libwebsockets] Initiating a write to select clients

Andy Green andy at warmcat.com
Sat Jan 30 13:42:32 CET 2016



On 01/30/2016 08:21 PM, Tortoise Mailbox wrote:
> Hello,
>
> My websockets server will have a number of clients connected to it
> simultaneously.  Each client will be interested in different
> information.  The server will send data to the clients under 2
> conditions: periodic updates, or on detection changed data.  Different
> clients will request updates at different intervals e.g., a phone with
> limited bandwidth might request updates every 10 seconds, but a desktop
> browser might request updates every 1 second.  How do I initiate writing
> to select clients using libwebsockets?  I may be mistaken, but the

LWS_VISIBLE LWS_EXTERN int
lws_callback_on_writable(struct lws *wsi);

> sample programs only show sending of data in response to receiving data,
> or sending data periodically to all clients (not specific clients).
> Also, is it possible to access the per-session data outside of the callback?

These are all the same issue actually, you want to hold your own list of 
wsi + user pointer (which you can acquire at ESTABLISHED callback and 
retire at the corresponding CLOSE callback).

If you look at the locking in the test-server-pthreads example, you can 
use this to guarantee a wsi will not disappear from under you in a 
different thread.  And it's safe to call lws_callback_on_writable() 
otherwise from the other thread.

-Andy

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



More information about the Libwebsockets mailing list