Tidhttp.connectTimeout 不起作用!

发布于 2024-10-04 02:36:43 字数 95 浏览 0 评论 0原文

所以我使用 tidhttp 来发出 post 请求。当我尝试将 connectTimeout 设置为任意时间段时,它都没有效果。在出现异常之前我仍然等待约 5 秒。 提前致谢!

So i'm using tidhttp to make post requests. when i try to set connectTimeout whatever period of time it has no effect. I still wait ~5 sec before i get exception.
Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

极度宠爱 2024-10-11 02:36:43

如果您要连接到主机名而不是 IP 地址,则必须通过 DNS 查找将主机名解析为 IP,这可能需要一些时间,尤其是在操作系统尚未缓存主机名的情况下。 ConnectTimeout 属性不考虑该时间。

此外,当 ConnectTimeout 不为零时,或者使用 TIdAntiFreeze 时,Indy 必须使用内部工作线程来对服务器执行实际的套接字 API connect() 调用。启动新线程可能需要一些时间,具体取决于当时可用的系统资源。 ConnectTimeout 也不考虑该时间。

ConnectTimeout 的当前实现仅适用于实际的套接字 API connect() 调用本身,不适用于达到该点所需的任何额外工作。因此,如果您设置了 5 秒的 ConnectTimeout 值,则在 TIdTCPClient.Connect() 退出之前可能会经过超过 5 秒。

If you are connecting to a hostname instead of an IP address, the hostname has to be resolved to an IP via a DNS lookup, which can take time, especially if the hostname has not been cached by the OS yet. The ConnectTimeout property does not account for that time.

Also, when ConnectTimeout is not zero, or if TIdAntiFreeze is being used, Indy has to use an internal worker thread to perform the actual socket API connect() call to the server. Starting a new thread can take some time, depending on available system resources at that moment. ConnectTimeout does not account for that time, either.

The current implementation of ConnectTimeout applies only to the actual socket API connect() call itself, not to any of the extra work needed to reach that point. As such, if you have a 5 second ConnectTimeout value set, it is possible to hanve more than 5 seconds elapse before TIdTCPClient.Connect() exits.

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