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.
How can I set a timeout so that idTelnet.Connect returns within nn ms
regardless of whether a connection has been established or not?
Yes, it will - eventually.
Or until the OS finally gives up and fails the connection, reporting an error that Indy will then raise as an exception.
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 aTIdAntiFreeze
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.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 optionalATimeout
parameter. In Indy 10, theATimeout
parameter was replaced with a newConnectTimeout
property.