|
-
March 17th, 2005, 02:03 AM
#1
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
-
March 17th, 2005, 02:58 AM
#2
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.
Last edited by svenhag; March 17th, 2005 at 04:37 AM.
If you try and take a cat apart to see how it works,
the first thing you'll have on your hands is a nonworking cat
-
March 17th, 2005, 03:45 AM
#3
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
-
March 17th, 2005, 04:10 AM
#4
Re: Detecting closed connection
A RST will make recv return -1 with errno set to ECONNRESET.
Last edited by svenhag; March 17th, 2005 at 04:35 AM.
If you try and take a cat apart to see how it works,
the first thing you'll have on your hands is a nonworking cat
-
March 17th, 2005, 04:18 AM
#5
Re: Detecting closed connection
Voila,
thank you very much.
This will work for me.
Matze
-
March 17th, 2005, 04:34 AM
#6
Re: Detecting closed connection
Edit my posts a little since they were 'pre-coffee' posts :P and contained some errors.
If you try and take a cat apart to see how it works,
the first thing you'll have on your hands is a nonworking cat
-
March 17th, 2005, 04:53 AM
#7
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|