异步I/O模型下的WebSocket Client

前言:

最近写SOCC.js,封装到了WebSocket。

论坛上大部分的WebSocket Client基本都是同步Recv。

对于部分异步Recv,基本是调用封装的WebSocket Client(如HP-Socket)

于是我自己(面向MSDN编程)利用WSAAsyncSelect封装了一个异步的WebSocket Client

备注:

本程序的其他源码基础来自:[RFC 6455] WebSocket Client 模块纯源码实现以及分析

正文:

下面照抄MSDN对于WSAAsyncSelect的解释:

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不用再重新zc窗口消息。这给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。(虽然zc事件可以是同时多个事件,但是消息响应是一个一个来的。)

关于WSAAsyncSelect的一些解释:

参数“s”:A descriptor that identifies the socket for which event notification is required.(嵌套字标识符)

参数“hWnd”:A handle that identifies the window that will receive a message when a network event occurs.(接受消息的窗口句柄)

参数“wMsg”:A message to be received when a network event occurs.(事件发生时发给窗口的uMsg)

参数“lEvent”:A bitmask that specifies a combination of network events in which the application is interested.(监听的事件标识)

一些图片:

异步:

异步:

消息处理:

消息处理

相关文件下载地址
©下载资源版权归作者所有;本站所有资源均来源于网络,仅供学习使用,请支持正版!

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注