Delphi 6.如何设置idTelnet.Connect超时以在没有连接的情况下尽早返回 [英] Delphi 6. How to set idTelnet.Connect timeout for early return on no connection

查看:166
本文介绍了Delphi 6.如何设置idTelnet.Connect超时以在没有连接的情况下尽早返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

呼叫idTelnet.Connect通常会立即连接到远程设备.
但是,
如果远程设备没有响应, 那么对idTelnet.Connect的调用不会返回.
它等待来自远程设备的响应.

Calling idTelnet.Connect normally connects to the remote device instantaneously.
But,
if the remote device does not respond, then the call to idTelnet.Connect does not return.
It waits for a response from the remote device.

这会挂起整个应用程序.

This hangs the entire application.

如何设置超时,以便idTelnet.Connect在nn ms内返回
不管是否已建立连接?

How can I set a timeout so that idTelnet.Connect returns within nn ms
regardless of whether a connection has been established or not?

推荐答案

如果远程设备没有响应,则对idTelnet.Connect的调用不会返回.

if the remote device does not respond, then the call to idTelnet.Connect does not return.

是的,最终-

它等待来自远程设备的响应.

It waits for a response from the remote device.

或者直到操作系统最终放弃并导致连接失败,然后报告一个错误,然后Indy将引发异常.

Or until the OS finally gives up and fails the connection, reporting an error that Indy will then raise as an exception.

这会挂起整个应用程序.

This hangs the entire application.

这意味着您要在主UI线程的上下文中调用Connect(),而您首先不应该这样做.如果必须这样做,请至少在MainForm上放置一个TIdAntiFreeze组件(并准备处理可能引起的任何重入后果).否则,请将套接字代码移到单独的工作线程中.

That means you are calling Connect() in the context of the main UI thread, which you should not be doing in the first place. If you must do that, at least place a TIdAntiFreeze component on your MainForm (and be prepared to handle any reentry consequences that may introduce). Otherwise, move your socket code to a separate worker thread instead.

如何设置超时,以便idTelnet.Connect在nn ms内返回,而不管是否已建立连接?

How can I set a timeout so that idTelnet.Connect returns within nn ms regardless of whether a connection has been established or not?

您没有说出您使用的是Indy的哪个版本. Delphi 6很老了.如果使用的是附带的Indy版本,则说明使用的是Indy 8或9.Connect()在Indy 8中根本没有超时功能.在Indy 9中,Connect()具有可选的ATimeout参数. .在Indy 10中,用新的ConnectTimeout属性替换了ATimeout参数.

You did not say which version of Indy you are using. Delphi 6 is very old. If you are using the version of Indy that shipped with it, then you are using Indy 8 or maybe 9. Connect() has no timeout functionality at all in Indy 8. In Indy 9, Connect() has an optional ATimeout parameter. In Indy 10, the ATimeout parameter was replaced with a new ConnectTimeout property.

这篇关于Delphi 6.如何设置idTelnet.Connect超时以在没有连接的情况下尽早返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆