recovering from “Connection Reset By Peer” Indy TC

2019-02-05 02:33发布

How should I be recovering in this situation?

The server crashes, thus the connection has been abnormally closed. Calls to almost everything result in "Connection Reset By Peer" exceptions. I seem to have fixed it by calling Disconnect on the TIdTCPClient object inside the except block, but it results in one final exception with the same message (which I have caught in the second try-except block).

This is with Indy10 and 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;

标签: delphi tcp indy
1条回答
ら.Afraid
2楼-- · 2019-02-05 03:09

Try this:

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; 
查看更多
登录 后发表回答