Listen to disconnect tcp clients in google chrome app

The documentation for chrome.sockets.tcpServer and chrome.sockets.tcp doesn't mention anywhere how to listen for client disconnects. How can i do this?

I found out what you got resultCode == -15

in the function callback chrome.sockets.tcp.send

if the client was disconnected. But I really want to be notified if someone disconnects instead of just using a proactive method to check for it.

+3


source to share


2 answers


I understand that disconnecting sockets is not something the underlying OS can detect. There is no way at the socket level to tell the difference between a client who left and a client who might just take the time to send the next packet. Perhaps someone with deeper knowledge of TCP / IP will fix me, but this is always the answer I have seen.



You can send a disconnect message to the clients at the application level, otherwise a periodic heartbeat may occur, without which the server will shut down with the client. More details here: Is TCP Keepalive the only mechanism to detect a broken link?

+1


source


I thought chrome.sockets gave you an onReceived event with a byteLength packet of 0, which means they are disabled, right? I mean, how would I gracefully disconnect, send a payload with 0 bytes.



0


source







All Articles