[Libwebsockets] How to send messages frequently ?

Andy Green andy at warmcat.com
Sun Jan 22 00:38:03 CET 2017



On 22 January 2017 04:15:02 GMT+08:00, hanguofu <hanguofu at 163.com> wrote:
>I develop an application based on example libwebsockets-test-client.
>The application has 2 threads : in main thread there is routine
>callback_dumb_increment  and the message loop : lws_service(context, 50
>);
>
>
>At the other thread , the application send messages with
>lws_callback_on_writable.
>Unfortunately , the interval of message vary much and it may be as 
>short as 1 millisecond sometimes.

On the network, with tcp, you are not really in control of sending stuff like that.

Once the tcp window is filled, your kernel will not accept to buffer anything more, let alone send it.

The reality is the receiver and every step between decides when you may send something.  You can 'have something new to send every ms' but there's nothing to say you will be able to send it within any time limit.

So there's maybe a conceptual problem here between how tcp network programming really works and how you are thinking about what you are trying to do.  Udp lets you do this kind of sending but ws is tcp only, and udp offers no guarantee your packets will actually arrive.

>Is it a must to change the message loop interval to 
>lws_service(context, 1 ) ? I found out some messages are dropped 
>without any notice if  the "Timeout for poll" is large .

What is your platform and lws version?

Are we using ssl?

What do we mean 'messages are dropped', it means the ones you are sending?

-Andy

>
>Regards !
>
>
>Guofu Han

-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.



More information about the Libwebsockets mailing list