How to disconnect the TCPClient Totally ? (Indy)

Kermia picture Kermia · Aug 26, 2010 · Viewed 11.2k times · Source

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 totally ?

Thank you

Answer

sabri.arslan picture sabri.arslan · Aug 26, 2010

using at indy 10 you must sure inputbuffer is empty.

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