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;
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With