WSAAsyncSelect 实现给异步socket给了另一种实现方式,就是通过窗口消息的方式来提醒对socket接收还是发送
msdn有非常全面的解释:https://msdn.microsoft.com/en-us/library/windows/desktop/ms741540(v=vs.85).aspx
本文几解释以下我认为难懂的几点:
1.The socket created by the accept function has the same properties as the listening socket used to accept it.
由listen socket 的accept返回的socket和listen的socket 具有同样的属性。意味着accept返回的socket不用再重新注册窗口消息。这给socket服务器提供了便利。
2.When one of the nominated network events occurs on the specified socket s, the application window hWndreceives 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.
wParam标识哪一个socket发生了事件,LOWWORD(lParam)表示当前发生的是哪个事件(是接收还是发送) 而HIWORD(lParam ) 标识错误代码
3.Although WSAAsyncSelect can be called with interest in multiple events, the application window will receive a single message for each network event。
虽然注册事件可以是同时多个事件,但是消息响应是一个一个来的。
下面附上我今天写的Socket 服务端。是由上一篇博文里的Server端修改而来。