Since you are encountering the same problem in multiple wrappers that all ultimately delegate to Winsock, its safe to assume that this is an OS issue, not a coding issue. Something on your system has hosed your Winsock installation, or the OS is having networking problems in general, especially since a simple OS reboot did not clear the issue. Try using Windows' command-line netsh
tool to reset both the TCP and Winsock subsystems, the command-line ipconfig
tool to flush the DNS cache, reboot, and see if the problem continues.
On the coding side, you should implement a timeout on the connect()
to avoid further deadlocks. There are two ways to do that:
Put the socket into non-blocking mode and then call
select()
ifconnect()
returns aWSAEWOULDBLOCk
error. Ifselect()
times out, close the socket.Leave the socket in blocking mode and use a separate thread to manage the timeout. Call
connect()
in the thread, or run your timeout logic in the thread, it does not really matter, but if the timeout elapses whileconnect()
is still running then you can close the socket, abortingconnect()
. This is the approach thatTIdTCPClient
uses.