在这种情况下,我应该如何进行恢复?
服务器崩溃了,因此连接被异常关闭。几乎所有调用都会导致“Connection Reset By Peer”异常。通过在except块中对TIdTCPClient对象调用Disconnect方法似乎已经解决了这个问题,但最终会出现一条相同消息的异常(我已经在第二个try-except块中捕获了这条异常)。
这是使用Indy10和Delphi XE2。
try
if not EcomSocket.Connected then EcomSocket.Connect();
except
on e: Exception do begin
try
EcomSocket.Disconnect();
except
MessageDlg('Connectivity to the server has been lost.', mtError, [mbOK], 0);
end;
end;
end;