Link to home
Start Free TrialLog in
Avatar of leafarsetnofis
leafarsetnofis

asked on

How to handle 10054 socket error?

I need to handle the socket error 10054 (Conection reset by peer). I'm using try/except but when the exception raised is impossible to reconnect the socket, the only way to reconnet with server is closing the application and start again.
Anybody know how to handle this exception withou restarting the application in order to reconnect to server when the app raise the exception?
Avatar of 2266180
2266180
Flag of United States of America image

this sounds like you are working with indy. in case of indy you *MUST* let the indy exceptions fly out.

so do womething like this:

try
  blabla with indy
except
  on e:EIdException do
    raise e;
  on e:exception do
    do whatever with other exceptions.
end;
In your exception-handler, ensure the socket is closed and then re-connect it. You should not need to restart the app!

Avatar of leafarsetnofis
leafarsetnofis

ASKER

Ok, Ciuly, I tried your tip, indy raise exception...but its the same: can't reconnect to the server...

kenpem: I'm not sure how to verify if the socket is closed or not... I tried with:
      If IdTCPClient1.Socket.Connected then....
but the app raise the same exception: 10054 ..etc...

I closed the connection in code when the exception occur (is a dial up connection) an then reconnect to the ISP and the socket reconect ok (Without restart the app!) . But I don't think it's the best way to handle this exception.

Can you explain me how to verify if the socket is closed withou raise the exception?
Thanks to all.

Hi,

If it can help, see eventually there and http://www.indyproject.org/KB/:

http://www.sockets.com/err_lst1.htm#WSAECONNRESET (the reason of error)

and

http://www.sockets.com/err_lst1.htm#WSAECONNABORTED for cheks to perform.



ASKER CERTIFIED SOLUTION
Avatar of 2266180
2266180
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TheRealLoki
did you write the "server" you are connecting to?