[Libwebsockets] Fwd: How can i send array strings to browser on all websockets

"Andy Green (林安廸)" andy at warmcat.com
Wed Jan 1 13:12:12 CET 2014

On 01/01/14 19:55, the mail apparently from satya gowtham kudupudi included:
> test-server is copying data to all the sockets. Now how can I write to
> only a specific category of sockets? I think pollfds array should help
> me here. Should I have to maintain a pollfds array for each channel,
> push the websocket into pollfds array and service the pollfds?

There's a few different ways that can solve it.

Mutiple poll() isn't a good idea because lws is singlethreaded, and if 
you're waiting on one poll set you can't wait on another unless you use 
epoll() which we don't support.

Probably the thing to consider most is what happens in these 
"channels"... they only broadcast a few bytes now and again?  How many 
channels might there be on a server?  if you're on a channel, is it 
always streaming new data out or goes silent for long periods?

If not much happens on a channel, there aren't many different channels 
and there'll all mainly silent, it can be worth making everybody 
callback when writable and in their user callback for that they look if 
their channel has anything to send, otherwise just return.

If the channels may be busy with new data for long perioids, another way 
is track all the live wsi in a list (adding them in the ESTABLISHED 
callback and removing them in the CLOSED callback for that wsi) and 
track which channel the connection is associated with.  Then when there 
is new channel data, you can just call the "callback when writeable" 
function for wsi on that channel.

If the channel data is itself coming in on a socket, you can share those 
connections in the same poll() using the external poll loop support 
stuff cleanly.

If the data doesn't anyway all live on the server you'll also have to 
take care that not all of the clients may be cooperative in terms of 
taking data as quickly as you like.  Then you need a policy to kill the 
connection if they fall beyond what you're willing to buffer at the 
server for that "channel".


> Thanks!

More information about the Libwebsockets mailing list