Newsgroups : Borland : borland.public.delphi.internet.winsock : 2007 Dec : Re: how to check connection?
| Subject: | Re: how to check connection? |
| Posted by: | "Remy Lebeau (TeamB)" (no.spam@no.spam.com) |
| Date: | Wed, 2 Jan 2008 10:10:19 |
"Craig" <firebirdwebguy@hotmail.com> wrote in message
news:477723b7@newsgroups.borland.com...
> The issue is, are we connected to a peer?
Like I tried to explain to you earlier, there is no single reliable way to
do that, because the OS itself does not always have that information
available. The connection must be intentionally and gracefully terminated
in code, not by the user messing with the hardware, in order for the OS to
keep track of it properly.
> The ONLY way you can know if the socket is still valid is
> to test by sending data.
Reading or writing will do that. However, in the case of writing, a socket
has an outbound buffer. When you send a block of data to a socket, it is
merely put into the buffer and then the call exits right away, reporting the
number of bytes that were put into the buffer. The data is not always
transmitted right away. The socket transmits the buffer at its leisure
behind the scenes for optimal bandwidth usage (refer to the Nagle algorithm,
aka "send coalescing", for more details). If the connection is terminated
abnormally, the socket will happily continue allowing the application to
write data into the buffer successfully until it eventually fills up, at
which point the socket will enter a blocking state until the data is
transmitted (which it can't) or until the socket times out internally (which
can take a long time). So even sending data will not be able to tell you
for a potentially long time whether the connection is alive or dead. That
is why you usually need to implement your own timeouts and keepalives in
your own code to deal with abnormal disconnects.
Gambit
none