How can you tell a server has closed from the client side? I close my server before i close my client which has a loop in it that is now infinite because it is not recieving any input. So how can i tell the server has been closed from the perspective of the client. I am doing this all in python.
Asked
Active
Viewed 19 times
0
-
"It depends". UDP? No way to tell without implementing your own application-layer logic. TCP? Depends on settings, including connection flags. See [How to change TCP keepalive timer using Python script](https://stackoverflow.com/questions/12248132/how-to-change-tcp-keepalive-timer-using-python-script). If that doesn't answer your question, [edit] to add a [mre] so others can see exactly _how_ you're creating the socket -- if you're using a network framework other than the standard-library `socket` module, a different answer may be called for. – Charles Duffy Feb 20 '22 at 21:18
-
You might also do a general review of the search results for `site:stackoverflow.com python TCP keepalive`; there's quite a lot there. – Charles Duffy Feb 20 '22 at 21:21
-
(in _some_ cases you'll already get a RST from the server, causing the client to find out the connection is dead immediately; it's only the case where that doesn't get through that you need any of this in the first place). – Charles Duffy Feb 20 '22 at 21:22
-
I'm not sure this about detecting an abnormally disconnected server rather than a normally disconnected server that sends a FIN that makes it to the client. We'd need to see the client code, so I'd close the question because it lacks the necessary detail. – President James K. Polk Feb 20 '22 at 21:30