[Libwebsockets] Send messages to client from Server

Andy Green andy at warmcat.com
Thu Sep 25 08:51:31 CEST 2014



On 25 September 2014 14:46:39 GMT+08:00, SriHarsha <mynameissriharsha at gmail.com> wrote:
>Hey Andy,
>How are you ?
>
>I had a quick question about how to send messages from the server to
>the
>browser.
>
>Right now I am hoping when I receive a connection in my callback
>LWS_CALLBACK_ESTABLISHED
>I can store the pointer to the libWebSocket struct and use it later on.
>
>When I want to send the message from the server to my client I want to
>use libwebsocket_write
>and then pass the pointer that I had stored previous.
>
>Do you think this is a nice way to do it ?

No, the library does not work like that.

Look at the example apps and how they ask for a callback when the connection is writeable, and do any writing from that callback.

You can keep a wsi by following the lifecycle callbacks, but unless you have another thread that wants it (and he is only allowed to ask for a callback when it is writeable), you do not need to.

-Andy

>Any help is greatly appreciated.
>
>Thank you,
>H




More information about the Libwebsockets mailing list