4

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!

Peacelyk
  • 1,126
  • 4
  • 24
  • 48

1 Answers1

8

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.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • Thank you for your reply. I am connecty directly to IP address, i'm not using TidAntiFreeze. My connecttimeout is 1000ms, but it takes like 5000ms. I should maybe mention that i do many requests (to different urls/ip) with idhttp component. If the first request (via dns lookup) success and the second request (to a device) fails, then i takes mentioned time until i get timeout exception. But, if i disconnect my computer totally from network, then it works fine. – Peacelyk Nov 25 '10 at 20:25
  • A 1-second timeout is much too small. Just the overhead needed to reach the socket API connect() call could take more than 1 second. I would not recommend using a timeout that is less than 5 seconds, at the minimum. I prefer to use 10-30 seconds myself. – Remy Lebeau Nov 26 '10 at 07:44