Tech Support > Microsoft Windows > Development Resources > Socket programming: WSAAsyncSelect() not working properly
Socket programming: WSAAsyncSelect() not working properly
Posted by Dwij Aggarwal on January 12th, 2004


hello,
I am usning win 98 SE and visual studio 6.0
I wrote a client and a server. I used WSAAsyncSelect() to make recv()
non blocking in both client and server which is working perfectly. In
the server, i was using accept() in a while() loop which is making the
server blocking while listening because as soon as the user clicks
onthe "Listen" button, it enters into the following while loop and
blocks but when i connect using the client, it accepts it perfectly
and works.
// -start-
TempSock = SOCKET_ERROR;
while (TempSock == SOCKET_ERROR)
{
TempSock = accept(Socket, NULL, NULL);
}
Socket = TempSock;
DialogBox(hInst, (LPCTSTR)IDD_CHATBOX, hDlg, (DLGPROC)Chat);
// above dialog box opens up 2 edit controls to send and recv messages
}
// -end-
After this i thought of bringing this accept() out of while loop too
and i used:
WSAAsyncSelect(Socket, hDlg, WM_STARTACCEPT,FD_ACCEPT);
in the starting and used "case WM_STARTACCEPT: " to call the accept()
which is now not in any while loop.Now when i connect using the client
it shows me the error that my socket is not listening, error 10022 . I
dont know whats wrong. Any help will be greatful.
Thanks
Dwij Aggarwal

Posted by Paul Battersby on January 12th, 2004


I don't know if this will help but here is how I've handled socket
programming:

I called this to use the WM_USER message for socket events:

WSAAsyncSelect(socket,hwndMain,WM_USER,FD_ACCEPT | FD_READ | FD_CLOSE |
FD_WRITE);

then in the message loop:

LRESULT CALLBACK
MainWndProc (HWND hwnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
{
WORD eventType; /* used to get the type of socket event */

case WM_USER:
eventType = WSAGETSELECTEVENT(lParam);

switch (eventType) {
case FD_ACCEPT:
break;

case FD_READ:
break;

case FD_WRITE:
break;

case FD_CLOSE:
break;

} /* end switch */
}

"Dwij Aggarwal" <dwijaggarwal@hotpop.com> wrote in message
news:e3a86793.0401120854.3a590432@posting.google.c om...



Similar Posts