Holgerwa
Holgerwa

Reputation: 3460

Is it possible to terminate a TCPClient immediately?

My app sends data to a Server using a TidTCPClient. The Server uses a TidTCPServer. All works fine and I am now trying to handle unexpected situations.

When I disconnect the network cable between server and client, and then try to close the client, it waits for a long time, until it finally closes:

TCPClient.IOHandler.InputBuffer.Clear;
TCPClient.Disconnect;
TCPClient.Free;

TCPClient.Free is the place where it waits. This is sometimes 30 seconds, sometimes even longer.

Is there a way to terminate a TCPClient immediately, no matter what it is doing at that moment?

Upvotes: 1

Views: 859

Answers (2)

Remy Lebeau
Remy Lebeau

Reputation: 596352

You should be clearing the InputBuffer after calling Disconnect(), not before.

In any case, there is no reason for a socket to cause such a hang when disconnecting/freeing the TIdTCPClient, unless you have messed around with the socket's LINGER options. So I have to suspect your own code is at fault first. Which version of Indy are you using? Do you have any event handlers assigned to the TIdTCPClient? Have you tried stepping through TIdTCPClient's destructor in the debugger to see what is really happening?

Upvotes: 1

Marco van de Voort
Marco van de Voort

Reputation: 26356

It probably waits for a timeout. Look at the properties of the component to lower the timeout value

Upvotes: 0

Related Questions