[Libwebsockets] R: R: Newbie: is it possible to generate data from server?
stefano.mora at newdep.com
Fri Sep 28 11:25:40 CEST 2018
great primitives 😊
In the sample the ring is accessed from the LWS_CALLBACK_RECEIVE, where it has the vhd pointer.
About my application I'm in a trouble..
In timer handler I cannot access to lws_ring_* function cause I don't have the vhd or ring pointers.
On the other hand, I'm not sure that when (in the timer handler) I save the data in a buffer and recall lws_cancel_service() function, the LWS_CALLBACK_EVENT_WAIT_CANCELLED callback will receive the 'untouched' data to store it in the ring (and let the LWS_CALLBACK_SERVER_WRITEABLE consume it).
Practically, how can I feed the ring from the timer handler?
Da: Andy Green <andy at warmcat.com>
Inviato: venerdì 28 settembre 2018 10:34
A: Stefano Mora <stefano.mora at newdep.com>; libwebsockets at ml.libwebsockets.org
Oggetto: Re: R: [Libwebsockets] Newbie: is it possible to geenrate data from server?
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
> 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