![]() |
| | #1 |
| Registered User Join Date: Jan 2005 Location: Estonia
Posts: 131
| WSAEWOULDBLOCK and WSAEISCONN I wrote this code: Code: SOCKET sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
sockaddr_in socket_address;
//snip - initialize the socket_address' members - snip//
int status = 1;
ioctlsocket(sock, FIONBIO, &status); //set the socket in non-blocking mode
while (1)
{
int ret = connect(sock, (sockaddr*)(&socket_address), sizeof(socket_address));
if (ret == -1)
{
cout << "Connection error : " << WSAGetLastError() << endl;
Sleep(50); //wait a bit to not hang the CPU
}
else
{
cout << "Connection succeeded" << endl;
break;
}
}
WSAEWOULDBLOCK - the connect function would block, try again later WSAEISCONN - the socket is already connected, why are you trying to connect it again? (ofcourse the output is written in numbers, but I translated the error codes and added my comments on what they mean imho). So, what's wrong(firt it says: try again later, but later, it says that the socket is already connected)? |
| hardi is offline | |
| | #2 |
| Mad Join Date: Jan 2005 Location: Umeå, Sweden
Posts: 555
| Don't connect() with the socket again. To find out when the connection is established you can check if the socket is writable or use asynchronous sockets. |
| OnionKnight is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|