从恢复“连接重置由对等”印TCP客户端(recovering from “Connection Re

2019-06-24 06:54发布

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

服务器崩溃,从而连接已异常关闭。 调用几乎所有导致异常“重置由对等连接”。 我似乎通过调用断开内部的TIdTCPClient对象除了块上有固定的,但它导致具有相同的消息(我还夹在第二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;

Answer 1:

试试这个:

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; 


文章来源: recovering from “Connection Reset By Peer” Indy TCP Client
标签: delphi tcp indy