
| Subject: | IdTCPClient thinks its still connected [Edit] |
| Posted by: | Ben D |
| Date: | Mon, 31 May 2010 |
Hi,
I have a strange problem that I have tried all kinds of things to fix.
I have an application with a TIdTCPClient, and another application with a TIdTCPServer. the client connects, and the client sends requests in XML, and the server responds with data in XML.
This all works very well, except for when I disconnect the server abruptly - by quitting the server application while the client is still connected.
on the next attempt to send, the client gets the "connection closed gracefully" exception. at this point, the client application attempts to reconnect, but when this is tried, an "Already Connected" exception is generated, even though the server application is completely gone.
I have tried many things - in the initial exception handler on send, when the exception for connection closed is generated, I have tried calling TCPClient.Disconnect, TCPClient.IOHandler.Close, TCPClient.IOHandler.CheckForDisconnect.... many things to ensure that the client knows the connection is closed. I even try calling TCPClient.IOHandler.DiscardAll before calling disconnect, to make sure there is no data floating around that might cause the disconnect to fail.
....So the code moves on and tries to reconnect. before the reconnect, I call TCPClient.CheckForDisconnect again, to make sure the state is updated. I check TCPClient.Connected, and it is True. if I check TCPClient.CheckForDataOnSource, this is False. now, when I call TCPClient.Connect, I get the "Already Connected" exception.
What am I doing wrong?
I am using Indy Tiburon (r3842) in Delphi 2007 (v11.0.2902.10471)
thanks
ben
Edited by: Ben D on May 31, 2010 9:07 PM