Yes, the only way to know if the connection is still there is trying to
send something over it and if the connection is down, you will get a
message from the network layer telling you so.
No that has nothing to do with my (hopefully everyone got that) funny
comment. If the only way to communicate with your peer is torn down, then
it cannot notify you that it lost the connection - except by using
telepathy. Basically that was my point. Also you can have commands that do
not cause any immediate response, like "DO COMPLEX CALCULATION". Some
protocols always acknowledge anything, some don't. If you know you should
receive an answer immediately but you don't, then you know that somethings
wrong. But if not, well then you know nothing actually.
Well that depends on how the connection was set up. If you use the
TCPKeepalive option or do that yourself, then you will see packes going
back and forth. However if you do not do that, which is the normal way,
then you can have an established TCP connection that stays connected for 10
hours without sending a single byte during that time and then continue
later to send some data. A normal TCP connection that is established and is
idle does not send anything at all.
In fact, you can establish a TCP session, which stands idle, disconnect the
cable, wait an hour, put it back in and resume as if there was nothing.
Because for TCP, there actually *was* nothing exceptional, if both sides
didn't try to send data during that time which would have caused a
connection teardown. Note that some OS tear down all connections once you
pull the cable, so in that case just pull the cable at your modem or router
upstream.
There are servers that disconnect after inactivity, or send a
noop/keepalive after some time to see if you're still there, but that is
entirely protocol stuff which you can do if you want.
From the network point of view however, it is a problem that is
undetectable without sending data which is why I wrote the part about
telepathy in the first place.
You get one iff you try to send data after the connectivity is gone.
However if you just listen, how do you expect anything to come through when
the cable has been pulled somewhere and data is no longer able to reach you
? That is the basic problem and the one solution left is telepathy
Well that analogy is wrong - the dialtone is part of the connection setup
procedure and there you also get a lot of exceptions in TCP if there is a
problem. Look at it this way: You call me or I call you on the phone. We
talk a little. Then after a while we don't have anything more to say
immediately so we both just lay the phone down (but we're not hanging up,
just putting it on the desk) now I walk away, get some coffe, watch a TV
show, whatever. 3 hrs later I come back to the desk. How should I know
wheter you are still on the other side without taking the phone up and
asking you something which you must reply ? How should I have been notified
(by what?) during the time where I was drinking coffe or watching TV that
the connection just died ? With telepathy, this problem is solvable,
without it isn't.
And there is a huge difference between a connection switched network like
the telephony system and a packet-oriented stream protocol like TCP,
anyway.
On Windows, if a file is open, it cannot be erased, on Unix however, this
is very possible. The filehandle then remains open and valid, but the
directory entry for the file disappears, so any access from another process
will fail, because the file is simply no longer around, while the one who
still got it open can *still* read from it and doesn't know that the file
has been deleted. The file only gets effectively removed after the last
process closes the file handle, but it cannot be accessed or seen by other
processes starting from the moment it was deleted (actually unlinked from
the directory structure).
But this is again another thing altogether. TCP is not a file, compare it
to your postal service and you are sending (real) packets to your
destination. If your destination dies or moves away and cannot/does not
inform you beforehand, you will only know of that fact after you try to
send a packet and you get it back with a notice that the recipee's deceased
or the address became invalid. But if you just wait to receive any packet -
well you can wait forever, none will ever come from there again. And this
is exacly what happend to the OP and this behaviour, well is not possible
to solve by just waiting for appearing data (packets). You must send
packets either on the application level or at the network level using
TCPKeepAlive or have some sort of timeout mechanism that just closes the
connection when nothing more comes after X seconds.
Well the question certainly is not "dumb". It may sound strange if you
don't know it and haven't thought it through. I've been working with
networking stuff for many years now and it is a basic problem in that sort
of communication and just not solveable without actually testing the
connection by sending data. Wheter the network infrastructure does that for
you or you need to do it yourself is more or less irrelevant. I knew that
and made a little bit fun with my telepathy sentence (but I also gave the
solution to the problem)
Hopefully this now quite long post makes it clear why this is so. But if
not, just ask.
CU
René