Use WSAGetLastError
to find out why the call has failed. connect
returns 0 on success or SOCKET_ERROR
on failure.
You commented that WSAGetLastError
returns WSAEWOULDBLOCK
which states:
This error is returned from operations on nonblocking sockets that cannot be completed immediately, for example recv when no data is queued to be read from the socket. It is a nonfatal error, and the operation should be retried later. It is normal for WSAEWOULDBLOCK to be reported as the result from calling connect on a nonblocking SOCK_STREAM socket, since some time must elapse for the connection to be established.
So is expected behaviour on the non-blocking socket you have set up.