开发者

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 wait开发者_开发问答s 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?


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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜