[Libwebsockets] Is ws_ping_pong_interval the only way to find out dis-connected clients ?

Andy Green andy at warmcat.com
Sat Feb 11 21:23:32 CET 2017



On 11 February 2017 22:35:02 GMT+08:00, hanguofu <hanguofu at 163.com> wrote:
>
>
>
>
>At 2017-02-11 04:37:16, "Andy Green" <andy at warmcat.com> wrote:
>>
>>
>>On February 11, 2017 1:21:02 AM GMT+08:00, hanguofu <hanguofu at 163.com>
>wrote:
>>>Hi , there :
>>>
>>>
>>>I would like to maintain  a list of online clients at the server
>side.
>>>( Both of the clients and the server implement LWS library version
>>>2.1.0. ) So at the "LWS_CALLBACK_CLOSED" callback of the server , I
>>>deleted the dis-connected peer from the list. Unfortunately ,
>sometimes
>>>it does not work : the peer dis-connected without server's notice.
>>
>>What happens when you get that situation?
>
>
>The disconnected client seems O.K. At least , according to the log file
>of the
>disconnected client , it exits normally with "NOTICE:
>lws_context_destroy"  
>and "LWS_CALLBACK_CLOSED" callback is called --- the logic/program at
>the
>client side functions.
>However, the server didnot know the interested client was disconnected
>, so
>it sent messages to the client as usual. After a while , it finally
>finds out :
>the  "LWS_CALLBACK_CLOSED" callback is triggered and the peer is
>removed from the list.
>
>
>Of course , the greatest lost is the sent messages , gone with the wind
>too:(
>Is that what you are asking ?

What I wanted to know was how the server eventually found out and the reaction.  It found out by not getting ACKs for his writes, that is the same method as the ping/pong is going to do, except the latency of finding out is controlled.

Usually if communication is workable the peers notify each other at TCP level and lws finds out immediately and handles it.

But if you consider the client and server machines on ethernet, they communicate and then you pull out the ethernet cable of the client, no indication is generated for the server to understand something happened.  The client may get an indication he has lost ethernet carrier and exit normally.  Likewise, a client on an LTE link may enter a tunnel in a mountain or drop his phone in the sea, or his phone was a Note 7 ^^.  At least the user of the client knows his phone is on fire but the server was not informed because of sudden death of the device.

It's a basic network programming reality one peer may not get informed in a timely manner that the other peer has silently dropped.  Your data should expect it get lost if the peer is sleeping with the fishes, on fire, or cat pulled out the ethernet cable, etc.

-Andy

>
>
>Regards !
>
>
>
>Guofu Han
>
>
>
>
>
>
>>
>>>Is the ping-pong feature the only way out ?
>>
>>More exactly under some conditions it's only when you try to write to
>a silently "gone" peer that you can realize he's gone.  The ping / pong
>stuff will guarantee to provide writes on idle connections at
>intervals, so lws can know they are gone with a maximum latency and
>close them.
>>
>>-Andy
>>
>>>
>>>Regards !
>>>
>>>
>>>Guofu Han

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



More information about the Libwebsockets mailing list