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
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With