从"由Peer连接重置"Indy TCP客户端恢复

And*_*ark 10 delphi tcp indy

在这种情况下我该如何恢复?

服务器崩溃,因此连接异常关闭.对几乎所有内容的调用都会导致"对等连接重置"异常.我似乎已经通过在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;
Run Code Online (Sandbox Code Playgroud)

Rem*_*eau 9

试试这个:

try 
  if not EcomSocket.Connected then EcomSocket.Connect(); 
except 
  try 
    EcomSocket.Disconnect(False); 
  except 
  end; 
  if EcomSocket.IOHandler <> nil then EcomSocket.IOHandler.InputBuffer.Clear; 
  MessageDlg('Connectivity to the server has been lost.', mtError, [mbOK], 0); 
end; 
Run Code Online (Sandbox Code Playgroud)

  • 将“false”传递给 Disconnect 方法修复了它。它的默认行为是调用 DisconnectNotifyPeer,这触发了第二个异常。 (2认同)