Click to See Complete Forum and Search --> : WSAAsyncSelect


MasterDucky
November 14th, 2009, 01:32 PM
Hello!

I would like to know if i can put server and client side in the same code
when using WSAAsyncSelect?

Im asking this because we have to call WSAAsyncSelect in WinMain
and that way i would have to call 2 WSAAsynchSelect function call
(one for the client and one for the server) although i created two different sockets.

DrYap
November 22nd, 2009, 04:50 AM
Yes it is possile.

For your client do something like:

#define WM_CLIENT WM_USER+1
WSAAsyncSelect(clientSocket, hWnd, WM_CLIENT, FD_CONNECT|FD_READ);


and for the server do something like:

#define WM_SERVER WM_USER+2
WSAAsyncSelect(serverSocket, hWnd, WM_SERVER, FD_WRITE|FD_READ);


Then handle server responces with WM_SERVER in the WndProc and client responces with WM_CLIENT.

MasterDucky
November 26th, 2009, 08:37 AM
Awesome! Thanks a lot DrYap!

In the meantime i read this on a thread:

"Dont use WSAAsyncSelect, it demands a window, and it chokes that window's message queue when the network load is high, so the whole GUI locks up on you. Even one socket can lock your GUI when its working hard, thats just not cool.

Use the Select api, or better yet, use WSAWaitForMultipleEvents (up to 64 sockets per thread).

"
Is this true?

Thanks!

FilipDimitrov1967
November 27th, 2009, 04:09 AM
Perhaps, use thread to build up full packets (they are comming in chunks) and whatever other processing is possible before to send GUI update message.
But this is in case of heavy communication as its said.

MasterDucky
November 27th, 2009, 04:58 AM
Ok, thank you!

So for a simple chat application WSAAsyncSelect is perfect enough.