Skip to main content
gamedev.net
🔒 Locked

Getting multiple socket activity using Windows messages

Started by Dookie 2 replies 1.6k views
Original Post
Dookie
Dookie
Hey guys, here's an easy one for you! [smile] I don't know a whole lot about Windows messages, so I need your help... Here's what's currently in my game:
WSAAsyncSelect (srvr_socket, hDlg, WM_SOCKET, (FD_CLOSE | FD_CONNECT | FD_READ));
This lets me monitor the socket 'srvr_socket' through the Windows message 'WM_SOCKET', which is defined as WM_SOCKET = WM_USER + 1. Now, here's my question... What if I have three sockets I wish to monitor; for example, srvr_socket, client_socket and chat_socket? How do I monitor those three sockets using Windows message system? Thanks in advance for the help!
"The crows seemed to be calling his name, thought Caw"
hplus0603
hplus0603
You could call WSAAsyncSelect() for each socket. You find out which socket the message you get back is for by checking the wParam of the message.

Quote:
From MSDN:
When one of the nominated network events occurs on the specified socket s, the application window hWnd receives message wMsg. The wParam parameter identifies the socket on which a network event has occurred. The low word of lParam specifies the network event that has occurred. The high word of lParam contains any error code. The error code be any error as defined in Winsock2.h.

enum Bool { True, False, FileNotFound };
Dookie
Dookie
Hey, it's hplus0603 to the rescue. You rock! [grin]

Yeah, I sorta figured I'd have to call WSAAsyncSelect() for each socket. But what I couldn't figure out was how to name each Windows message identifier (is that what those are called?). Would the following work for what I'm trying to do?
#define WM_DATA		WM_USER+1#define WM_CLIENT	WM_USER+2#define WM_CHAT		WM_USER+3...WSAAsyncSelect (data_socket, hDlg, WM_DATA, (FD_CLOSE | FD_CONNECT | FD_READ));WSAAsyncSelect (client_socket, hDlg, WM_CLIENT, (FD_CLOSE | FD_CONNECT | FD_READ));WSAAsyncSelect (chat_socket, hDlg, WM_CHAT, (FD_CLOSE | FD_CONNECT | FD_READ));

Thanks again for the reply!
"The crows seemed to be calling his name, thought Caw"
hplus0603
hplus0603
Yes, that will work, but you can also just compare the "wParam" parameter in the message handler against the three sockets, to see which one it was that got the data.
enum Bool { True, False, FileNotFound };

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.