Jump to content
sBsaidus

Indy TIdTCPClient do not detect Disconnections.

Recommended Posts

Hello,

I have two(2) simple applications, A Server ( use TidTCPServer) and Client (use TidTCPClient) and they works well.

But when I close the server application, the client one do not indicate that it is disconnected, even the OnDisconnect Event not works.

This test is done on the same machine ( client & server are in the same machine (VM))

So, How can I see, or know that the server process does'nt exists or connection is lost in the client side.

PS: I use Delphi 7 all updates made, indy 10.6.2.

 

Thank you.

Share this post


Link to post

Indy uses blocking sockets and synchronous I/O. The client's OnDisconnected event is fired when the *client* disconnects on its end. If the server disconnects first, there is no real-time notification of that. The client will notify your code only when the client tries to access the connection and gets an error from the OS, at which time it will raise an exception to your code, such as EIdConnClosedGracefully, etc. So, if you want timely notification of a remote disconnect, you need to actively send/read data. If your code is not using the connection for lengths of time, use a timer  to poll for incoming data periodically. Or use a reading loop in a worker thread.

Edited by Remy Lebeau
  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×