C Board  

Go Back   C Board > General Programming Boards > Networking/Device Communication

Reply
 
LinkBack Thread Tools Display Modes
Old 12-17-2006, 06:31 AM   #1
Registered User
 
Join Date: Jan 2005
Location: Estonia
Posts: 131
WSAEWOULDBLOCK and WSAEISCONN

Hello.

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;
   }
}
I get this output:
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   Reply With Quote
Old 12-17-2006, 01:43 PM   #2
Mad
 
OnionKnight's Avatar
 
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   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump


All times are GMT -6. The time now is 06:54 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22