Tidhttp.connectTimeout 不起作用!
所以我使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您要连接到主机名而不是 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.