开发者

Is Indy TIdTCPClient suitable for local TCP/IP connections?

I need to connect to a device on the local network, using a TCP/IP connection. When I use a TIdTCPClient, all works well, except one thing:

If the connection is not available, it takes about 18-20 seconds before I get a timeout. The property ConnectTimeout has no effect, no matter what values I set. It always takes the same amount of time before a timeout.

This answer mentions long delay times for a timeout, and I am wondering if that's related to the Indy components?

I have to find out if the connection cannot be established very quickly, let's say within 1 second at most.

Is there a way to do this using Indy, or do I need to use different components / a different approach?

(I'm using the Indy 10 version that shipped with Delphi 2009)

EDIT:

I followed the instructions to upgrade Indy to the latest version in this post.

Still the same, it now consistently takes 22 seconds until TCPClient.Connect returns when th开发者_StackOverflow社区ere is no connection. ConnectTimeout and/or ReadTimeout seem to have no influence on this.


ConnectTimeout works correctly for 2010 and XE. Perhaps you can update your Indy version to the latest (its free). I have a function that does 'quick check' connects, just to check availability of the device and those timeouts are 5 seconds without problems (in both 2010 and XE).


With a default TCP client connect timeout (not specifically set) and a read timeout of 1 second, using Delphi 2010 and the latest Indy version, a local connection (using localhost as the host name) times out in 1 second. So this is definitely not a Delphi/Indy issue. BTW, this gives me an EIdSocketError ("socket error # 10061 connection refused").


I had the same exact problem. Check out this StackOverflow post.

In short, because Indy threads are blocking, you will need to make a threaded process. Then in the primary application create a timer which will terminate the thread if it has not done what it is supposed to do in the time given.

After I implemented this is worked great.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜