完整点,增加对意外断线的判断:
if FTcpClient.Connected then
begin
try
FTcpClient.CheckForGracefulDisconnect(False);
//或你的Indy版本没有CheckForGracefulDisconnect方法,改用下面的
//ReadFromStack(False, 1, False);
except
FTcpClient.Disconnect;
end;
end;
if not FTcpClient.Connected then
begin
try
FTcpClient.Connect;
except
FTcpClient.Disconnect;
end;
end;