Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Indy TCP Client Disconnection From TCP Server

Status
Not open for further replies.

ajbufort

Programmer
Apr 4, 2004
50
US
Hello All,

I have a client/server pair of programs in which the client makes a connection to the server, and then the connection can potentially lie dormant for a time until commands are sent back and forth. During this dormant state, I want to be able to fire a TCP-client-disconnected event if the user of the client program decides they wish to log off of the TCP server. I use:

Code:
TCPClient.Disconnect;

to try and accomplish this, but it seems the TCPServer.OnDisconnect method is never triggered - UNLESS the server is attempting to do:

Code:
AThread.Connection.ReadLn();

while the client disconnects.

Do I have to be reading from the connection in order to fire this event? Being forced to do this messes up the flow and functionality of my program as currently written.

-Tony
 
Well, for anyone who is interested, I found a way to get around the need for using a ReadLn, but it is only useful for people in certain circumstances. The circumstances, to be brief, are ones in which you are willing or able to put an IdHTTPServer into the code for your TCP server. Doing this, you can send the web server a command via a url-based parameter and do an AThread.Connection.Disconnect() of the TCP thread on the server side. No need for any disconnection event to fire from the client, because you are now doing the disconnection at the source, so to speak. All the client needs to do is send the command, and then perhaps disconnect locally, if you want, with TCPClient.Disconnect(). I was already using a web server/TCP server combo, so fortunately I did not have to use the web server solely to implement this command.

-Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top