If you ever programmed networking applications then you should know that it is impossible to control the timeout for blocking sockets on calling connect() function. This timeout is controlled by the operating system and may last up to 45 seconds when you want to connect to a non-existing host. Since blocking sockets are very attractive due to their simplicity in usage comparing to non-blocking (asynchronous) sockets, such a limitation disappoints many developers. You can change the value of timeout globally for the system, but I would like to warn you to avoid making any changes of the operating systems, as these changes will affect ALL networking applications running on your computer. In most cases, such a behavior is not desired.
In order to solve this problem you can use the following trick.
Read the rest of this entry