开发者

How to disconnect the TCPClient Totally ? (Indy)

When my Tcpclient is working , with this code :

TCPClient.Disconnect;
TCPClient.Connect;

I get "raised exception class EIdAlreadyConnected with message 'Already connected.'." error still (whereas , it has been disconnected before) .

So , how can i disconnect it 开发者_如何学Ctotally ?

Thank you


using at indy 10 you must sure inputbuffer is empty.

if idTcpClient.connected then
begin
 idTcpClient.IOHandler.InputBuffer.clear;
 idTcpClient.Disconnect;
end;


You say it is disconnected, but you only gave the command to disconnect.

Network traffic takes time, and probably you reconnected before you were really disconnected.

Probably you need to monitor some connection state or event to wait till you really are disconnected.

... or try to process the exception and ignore it, using try..except


TCPClient.IOHandler.InputBuffer.Clear;
TCPClient.IOHandler.CloseGracefully;
TCPClient.Disconnect;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜