Detecting closed connection
Hi,
I'm using standard-winsock(2.0) writing a simple TCP server application.
First i listen to a port, then accept an incomming connection and then
doing some communication.
I know, if the client closes the connection gracefully a final Send with 0-Bytes is done.
Now my question:
Is it possible to detect anyhow, if the client closed the connection NOT gracefully,
for example removing the network-cable, killing his application, or something like this.
Any suggestions are welcome.
Matze
[555 byte] By [
matze42] at [2007-11-19 6:41:41]

# 1 Re: Detecting closed connection
If the application is killed then then kernel will close all open descriptors and when the socket gets closed, a FIN will be sent to the other side to indicate that the connection has been closed.
There's no way to know if the cable has been disconnected except if you send something and doesn't get an answer at all. Also when the cable is disconnected the connection is not closed. It will remain open on both sides and once you connect the cable again you will be able to continue the communication.
You might receive a RST if the cable is disconnected and the host is restared and then the cable is connected again. The connection will be ESTBLISHED on the other side and when that side retransmits the data a RST will be sent back from the restarted host.
# 2 Re: Detecting closed connection
Hi svenhag,
thanks for your reply.
What exactly do i receive when a RST is sent.
I know, that when a FIN is sent, i get 0 Bytes in a "recv" call.
I think the disconnected-cable-case i can live with.
Matze
# 6 Re: Detecting closed connection
Ah see,
don't mind.
It's still OK for me.
So i will go and get a cup of coffee too, to avoid
dangerous pre-coffee effects on my programming :) .
Greetings,
Matze