[Libwebsockets] R: Newbie: is it possible to geenrate data from server?
andy at warmcat.com
Fri Sep 28 10:33:49 CEST 2018
On 28/09/2018 15:57, Stefano Mora wrote:
> Thanks Andy,
> I added a lws_cancel_service(pED->context); call in each timed function that wants to send some data to client and a LWS_CALLBACK_EVENT_WAIT_CANCELLED handler.
> When the function wants to send data, it fills a global buffer and calls lws_cancel_service.
> Now the problem is that I have 3 functions recalled back-to-back from the timer handler and if two of them need to send data, often the second one overwrite the first data before it is sent.
> If I have more than one lws_cancel_service call, is there a way to differentiate each of them?
That's a problem for your code to interpret what you code wants to do.
It's not really the problem of lws to provide everything your code needs
to do. Otherwise nobody needs to pay you, right?
As it happens ringbuffer is also a primitive provided by lws...
You can use that, roll your own or whatever.
> -- Ste
> -----Messaggio originale-----
> Da: Andy Green <andy at warmcat.com>
> Inviato: venerdì 21 settembre 2018 14:37
> A: Stefano Mora <stefano.mora at newdep.com>; libwebsockets at ml.libwebsockets.org
> Oggetto: Re: [Libwebsockets] Newbie: is it possible to geenrate data from server?
> On 21/09/2018 20:28, Stefano Mora wrote:
>> Hi all,
>> I'm developing a simple websocket server based on minimal sample.
>> No problem when I need to reply to client but I'd like to generate
>> data from server and push them to client.
>> Is it possible?
> Sure... the client has to reach out first though and establish the ws connection.
>> Which wsi structure do I need to point ?
> If I understand you, you want the client to connect and then wait until the server decides something exciting happened and send a ws message.
> When the server wants to talk to the client, he just has to either call
> lws_callback_on_writable() or similar api
> ...if the guy who decides it should happen is on the same thread as the lws service, or if the decision is on another thread, then
> lws_cancel_service() to wake the service thread(s) and have them realize there is something to do.
> for an example of the latter.
>> Libwebsockets mailing list
>> Libwebsockets at ml.libwebsockets.org
More information about the Libwebsockets