Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disconnect the TCPClient Totally ? (Indy)

Tags:

delphi

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

Thank you

like image 648
Kermia Avatar asked Aug 26 '10 12:08

Kermia


3 Answers

using at indy 10 you must sure inputbuffer is empty.

if idTcpClient.connected then
begin
 idTcpClient.IOHandler.InputBuffer.clear;
 idTcpClient.Disconnect;
end;
like image 101
sabri.arslan Avatar answered Nov 11 '22 00:11

sabri.arslan


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

like image 2
Marco van de Voort Avatar answered Nov 10 '22 23:11

Marco van de Voort


TCPClient.IOHandler.InputBuffer.Clear;
TCPClient.IOHandler.CloseGracefully;
TCPClient.Disconnect;
like image 1
Massimo Fazzolari Avatar answered Nov 10 '22 23:11

Massimo Fazzolari