Delphi Indy - Eidconnclosures 优雅地使套接字无法使用

发布于 2024-12-18 12:14:41 字数 756 浏览 3 评论 0原文

场景:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

紫﹏色ふ单纯 2024-12-25 12:14:41

您只需调用 TIdHTTP.Disconnect(False)TIdHTTP.IOHandler.InputBuffer.Clear() 即可恢复。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文