Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi Indy - Eidconnclosedgracefully makes socket unusable

Scenario:

Delphi 2010 running the latest Indy version from svn trunk.

I have an application that uses a idHTTP to send http requests. This idHTTP is created only once and kept in memory as long as the application is running. I send a lot of web requests to the same http server (which is also an application developed by me).

I am using keep-alive to keep the socket connected.

After several requests, I get an EIdConnClosedGracefully on the client side, and no mather what I do after I get this exception, every follow request to the same server generates the same exception.

I have tried to disconnect, close the socket, clear the IOHandler buffer and nothing worked.

If I destroy the IdHttp object and recreate it after the exception occurs, everything works fine. But that is not what i want because I need to be connected to the server all the time (to avoid TIME_WAITS and so on).

Does anyone know how to handle EIdConnClosedGracefully exception on the client side and make the idHttp works after that exception occurs?

EDIT

I developed the web server myself, and i am sure not disconnecting after a client request. I know that this exception is ok, but what is not ok is the socket become unusable after that. Indy should recovery from this exception, disconnecting the socket and reconnecting it when needed. As I said, this exception is being shown to the user, not only on Delphis IDE. What i really need is an way of after getting this exception, i must be able to continue using this socket. –

like image 991
Rafael Colucci Avatar asked Nov 28 '11 12:11

Rafael Colucci


1 Answers

Calling TIdHTTP.Disconnect(False) and TIdHTTP.IOHandler.InputBuffer.Clear() should be all you need to recover.

like image 54
Remy Lebeau Avatar answered Nov 08 '22 18:11

Remy Lebeau