Asyconous socket on Winsock2

Started by
2 comments, last by JMing 23 years, 1 month ago
i can create CreateSocket( Socket for request connect ) in not useAsynconous !!BUT when i use Asyconous it error. Error on my server is 10038 (WSAENOTSOCK).!! what can i do??? int G3DSock::CreateClient(char *IP) { sockaddr_in Target; CSocket = socket( AF_INET, SOCK_STREAM, 0 ); //////This Line//////// WSAAsyncSelect(CSocket, App->m_hWnd, WM_CSOCKET, (FD_CLOSE|FD_READ|FD_CONNECT)); /////////////////////////////// Target.sin_family = AF_INET; Target.sin_port = htons (5555); Target.sin_addr.s_addr = inet_addr(IP); //request to connect if( connect(CSocket, (sockaddr*)&Target, sizeof(Target)) == SOCKET_ERROR) { if (WSAGetLastError()==WSAEWOULDBLOCK) { Sleep(750); connect(CSocket, (LPSOCKADDR)&Target, sizeof(Target) ); return 1; } sprintf(App->SockBuffer,"Error: %d",WSAGetLastError() ); MessageBox(App->m_hWnd,App->SockBuffer,"Error", MB_OK); WSACleanup (); geEngine_Printf(App->Engine,300,300,"Can not connect"); return 1; } return 0; }
Advertisement
What type of variable is CSocket?

It should be a SOCKET. If not that is your problem caus the
MSDN Library says:

[qoute]
WSAENOTSOCK: The descriptor is not a socket.
[/qoute]

Hope this helps,
Jason

ill-lusion.com

ziggy@ill-lusion.com
laxdigital.com
[email=ziggy@laxdigital.com]ziggy@laxdigital.com[/email]
CSocket is SOCKET. (program work in blocking)
i think WSAEWOULDBLOCK is hapen.
how i can solve it ???
okay, WSAWOULDBLOCK is not *really* an error in this case. Simply
pass over it (set up a catch if statement to ignore it)...

new connect statement...
  if ( connect(CSocket, (sockaddr*)&Target, sizeof(Target)) == SOCKET_ERROR ){ if (WSAGetLastError()!=WSAEWOULDBLOCK){sprintf(App->SockBuffer,"Error: %d",WSAGetLastError() );MessageBox(App->m_hWnd,App->SockBuffer,"Error", MB_OK);WSACleanup ();geEngine_Printf(App->Engine,300,300,"Can not connect");return 1; }}  


Once you make the connect() call, you have to wait for a
FD_CONNECT message. Then test for connect errors. (use WSAGETSELECTERROR())

so in short- ignore the WSAWOULDBLOCK error, since it''s simply
telling you that the connect() has blocked the socket from
further activity (until an FD_CONNECT).

Jason

ill-lusion.com

ziggy@ill-lusion.com
laxdigital.com
[email=ziggy@laxdigital.com]ziggy@laxdigital.com[/email]

This topic is closed to new replies.

Advertisement