Newsgroups : Borland : borland.public.delphi.internet.winsock : 2008 Jan : Re: Connection reset by Peer
| Subject: | Re: Connection reset by Peer |
| Posted by: | "Remy Lebeau (TeamB)" (no.spam@no.spam.com) |
| Date: | Tue, 22 Jan 2008 12:03:25 |
"Michael Stieler" <michael.stieler@rie.eu> wrote in message
news:479619da$1@newsgroups.borland.com...
> I have the following problem with Indy 10.1.6:
That is a very old version. The current version is 10.2.3. You should
consider upgrading.
> - I check for ReadLnTimeout or exceptions in this call
> - If one of these occure, I call conn.Disconnect
You should always call Disconnect() when you are done with the connection.
> Now I do something the program can't handle: I remove the
> network cable from the computer.
You should not be doing that in the first place. That is a very poor way to
test unexpected disconnects.
> => The ReadLn call throws an exception: Socket Error # 10054
> Connection reset by peer.
There is no standard that says what kind of error is generated when pulling
out the cable. There is no guarantee that an error will even be generated
at all. That is strictly up to the OS to decide, and I have seen different
things happen on different OSs.
> If I call the Connected Function it ALSO throws the same exception
> and Connect doesn't work either.
The Connected() method has to read from the socket in order to determine its
status.
> So I tried the following work-around to close the connection:
That is redundant. You don't need to call Connected() first. Just call
Disconnect() by itself. It will either succeed or fail:
try
conn.Disconnect;
except
end;
> But even this doesn't allow me to call conn.Connect at a later
> time, because the exception is again thrown.
Then the socket is not fully closed.
> How can I leave this state?
Destroy the TIdTCPClient instance and reinstantiate it anew.
Gambit