Socket Detection of Closed Server Connection

mantracourt

Member
Licensed User
Longtime User
It is unfortunate that there is no simple method to determine whether a remote server socket has closed its connection after you use a client socket to connect to it.
I have seen several suggestions in the forum but none actually help me.

Example: I connect to a remote server. At some point the remote server closes its socket. I have no way of knowing that I need to close and reconnect from my end.
Suggestions that the error event is raised from an AsyncStreams object is not correct if the server simply closes the connection.
Using the phone events to look for a network connection change does not help as a socket can be closed without any loss of network connection.

I can see a couple of options.
1- If I stop getting data I can assume a socket closure and attempt a reconnect. Not very helpful when the data arrival is intentionally intermittent.
2- I get the server to send some sort of heartbeat message (that could help with item 1 above) or to respond to a client ping type command. Neither of which helps when the server functionality is outside of your control.

Does anyone have any working solution to identifying when a connection is broken?

Thank you
 
Top