Winsock提供了一个有用的异步I/O模型。利用这个模型,应用程序可在一个套接字上,接收以Windows消息为基础的网络事件通知。具体的做法是在建好一个套接字后,调用WSAAsyncSelect函数。该模型最早出现于Winsock的1.1版本中,用于帮助应用程序开发者面向一些早期的16位Windows平台工作组(如Windows),适应其“落”后的多任务消息环境。应用程序仍可从这种模型中得到好处,特别是它们用一个标准的Windows例程(常称为“指向”),对窗口消息进行管理的时候。该模型亦得到了微软基础类(微软基本类,MFC)对象CSocket的采纳。
,
# include & lt; winsock2.h>,, # include & lt; tchar.h>,, # define PORT ,,,,, 5150,, 1024 # define MSGSIZE ,,,, # define WM_SOCKET  WM_USER + 0,, # pragma 评论(自由,“ws2_32.lib”),, LRESULT CALLBACK 指向(HWND,单位,,按钮,,LPARAM);,, int WINAPI  . WinMain (HINSTANCE 实例句柄,HINSTANCE hPrevInstance,, PSTR szCmdLine,, int iCmdShow),, {,, static TCHAR  szAppName [],=, _T (“AsyncSelect 模式”);,, HWND ,,,,,,,, HWND ,,, MSG ,,,,,,,,, MSG ,,, WNDCLASS ,,,, WNDCLASS ,,, wndclass.style ,,,,,,,,=, CS_HREDRAW |, CS_VREDRAW ,,, wndclass.lpfnWndProc ,,=, WndProc ,,, wndclass.cbClsExtra ,,,=, 0,,,, wndclass.cbWndExtra ,,,=, 0,,,, wndclass.hInstance ,,,,=, hInstance ,,, wndclass.hIcon ,,,,,,,,=, LoadIcon (NULL,, IDI_APPLICATION),,,, wndclass.hCursor ,,,,,,=, LoadCursor (NULL,, IDC_ARROW),,,, wndclass.hbrBackground =, (HBRUSH), GetStockObject (WHITE_BRUSH),,,, 时间=wndclass.lpszMenuName NULL ,,, 时间=wndclass.lpszClassName szAppName ,,, if (! RegisterClass(及wndclass)),, {,, ,,,MessageBox (NULL,, TEXT (“却;能够program requires Windows NT !”),, szAppName,, MB_ICONERROR),,,, ,,,return 0,,,, },, 时间=hwnd CreateWindow (szAppName,,,,,,,,,,,,,,,,,,,//, window class name , ,,,,,,,,,,,,,,,,,,,,,,TEXT (“AsyncSelect 模式”),,//,window caption , ,,,,,,,,,,,,,,,,,,,,,,WS_OVERLAPPEDWINDOW,,,,,,,,,//, window style , ,,,,,,,,,,,,,,,,,,,,,,CW_USEDEFAULT,,,,,,,,,,,,,,,//, initial x position , ,,,,,,,,,,,,,,,,,,,,,,CW_USEDEFAULT,,,,,,,,,,,,,,,//, initial y position , ,,,,,,,,,,,,,,,,,,,,,,CW_USEDEFAULT,,,,,,,,,,,,,,,//, initial x size , ,,,,,,,,,,,,,,,,,,,,,,CW_USEDEFAULT,,,,,,,,,,,,,,,//, initial y size , ,,,,,,,,,,,,,,,,,,,,,,空,,,,,,,,,,,,,,,,,,,,,,,,//,parent window handle , ,,,,,,,,,,,,,,,,,,,,,,空,,,,,,,,,,,,,,,,,,,,,,,,//,window menu handle , null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null nullWSAAsyncSelect模型