[Libwebsockets] How to send data asynchronously to the client?

Andy Green andy at warmcat.com
Sun May 18 03:48:38 CEST 2014

On 05/14/2014 10:59 AM, Prathamesh P Ghanekar wrote:
> Hi,
> 1)Is there a way to asynchronously send the data to the client? That is,
> without being in a callback, server spontaneously initiating data
> transfer to the client..!!

Libwebsockets is basically single-threaded.  But, with care from another 
server thread, you can call either

libwebsocket_callback_on_writable(), or

but you need to manage your own list of live wsi / connections with the 
first option (by tracking their creating and destruction in the 
ESTABLISHED and CLOSED callbacks).

You will get a LWS_CALLBACK_SERVER_WRITABLE as soon as it's possible to 
write on that connection then, and you should figure out what to write 
and write it from there.


> 2)If not this, then is there a way to handle this in the callback? That
> is, is there a ‘reason’ value, which will be entered inside callback
> (e.g. LWS_CALLBACK_SERVER_WRITABLE etc.), using which I can send data,
> evenif client is not sending the data (as in case of
> LWS_CALLBACK_RECEIVE, where action is triggered only when client sends
> data)!!
> Regards,
> Prathamesh
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Disclaimer~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Information contained and transmitted by this e-mail is confidential and
> proprietary to IGATE and its affiliates and is intended for use only by
> the recipient. If you are not the intended recipient, you are hereby
> notified that any dissemination, distribution, copying or use of this
> e-mail is strictly prohibited and you are requested to delete this
> e-mail immediately and notify the originator or mailadmin at igate.com
> <mailto:mailadmin at igate.com>. IGATE does not enter into any agreement
> with any party by e-mail. Any views expressed by an individual do not
> necessarily reflect the view of IGATE. IGATE is not responsible for the
> consequences of any actions taken on the basis of information provided,
> through this email. The contents of an attachment to this e-mail may
> contain software viruses, which could damage your own computer system.
> While IGATE has taken every reasonable precaution to minimise this risk,
> we cannot accept liability for any damage which you sustain as a result
> of software viruses. You should carry out your own virus checks before
> opening an attachment. To know more about IGATE please visit
> www.igate.com <http://www.igate.com>.
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> _______________________________________________
> Libwebsockets mailing list
> Libwebsockets at ml.libwebsockets.org
> http://ml.libwebsockets.org/mailman/listinfo/libwebsockets

More information about the Libwebsockets mailing list