Delphi Indy - Eidconnclosures 优雅地使套接字无法使用
场景:
Delphi 2010 从 svn trunk 运行最新的 Indy 版本。
我有一个使用 idHTTP 发送 http 请求的应用程序。该 idHTTP 仅创建一次,并在应用程序运行期间保留在内存中。我向同一个http服务器发送了很多Web请求(这也是我开发的应用程序)。
我正在使用 keep-alive 来保持套接字连接。
经过几次请求后,我在客户端收到一个EIdConnClosedGraceively
,无论我在收到此异常后做什么,对同一服务器的每个后续请求都会生成相同的异常 。
我尝试断开连接、关闭套接字、清除 IOHandler 缓冲区,但没有任何效果。
如果我销毁 IdHttp 对象并在异常发生后重新创建它,则一切正常。但这不是我想要的,因为我需要始终连接到服务器(以避免 TIME_WAITS 等)。
有谁知道如何在客户端处理 EIdConnClosedGraceively
异常并使 idHttp 在异常发生后正常工作?
编辑
我自己开发了网络服务器,并且我确信在客户端请求后不会断开连接。我知道这个异常是可以的,但是不好的是套接字在那之后变得不可用。 Indy 应该从这个异常中恢复,断开套接字并在需要时重新连接。正如我所说,这个异常正在向用户显示,而不仅仅是在 Delphis IDE 上。我真正需要的是一种在收到此异常后,我必须能够继续使用此套接字的方法。 –
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. –
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您只需调用
TIdHTTP.Disconnect(False)
和TIdHTTP.IOHandler.InputBuffer.Clear()
即可恢复。Calling
TIdHTTP.Disconnect(False)
andTIdHTTP.IOHandler.InputBuffer.Clear()
should be all you need to recover.