资源简介
socket I/O WSAAsyncSelect模型示例源码。visual studio工程。
代码片段和文件信息
//async_select_client.cpp: 定义应用程序的入口点。
//
#include “stdafx.h“
#include “async_select_client.h“
#include
#include
#include
#pragma comment(lib “Ws2_32.lib“)
const std::string kIP = “127.0.0.1“;
const u_short kPort = 10001;
#define WUM_SOCKET (WM_USER+1)
HWND g_hwnd;
void TraceMsgA(const char *lpFormat ...) {
if (!lpFormat)
return;
char *pMsgBuffer = NULL;
unsigned int iMsgBufCount = 0;
va_list arglist;
va_start(arglist lpFormat);
HRESULT hr = STRSAFE_E_INSUFFICIENT_BUFFER;
while (hr == STRSAFE_E_INSUFFICIENT_BUFFER) {
iMsgBufCount += 1024;
if (pMsgBuffer) {
free(pMsgBuffer);
pMsgBuffer = NULL;
}
pMsgBuffer = (char*)malloc(iMsgBufCount * sizeof(char));
if (!pMsgBuffer) {
break;
}
hr = StringCchVPrintfA(pMsgBuffer iMsgBufCount lpFormat arglist);
}
va_end(arglist);
if (hr == S_OK) {
OutputDebugStringA(pMsgBuffer);
}
if (pMsgBuffer) {
free(pMsgBuffer);
pMsgBuffer = NULL;
}
}
LRESULT CALLBACK WndProc(HWND hWnd UINT message WPARAM wParam LPARAM lParam)
{
int err;
SOCKET s;
char buf[100] = { 0 };
switch (message) {
// (4)
case WUM_SOCKET:
if (WSAGETSELECTERROR(lParam)) {
closesocket((SOCKET)wParam);
TraceMsgA(“connect failed %d\n“ WSAGETSELECTERROR(lParam));
break;
}
switch (WSAGETSELECTEVENT(lParam))
{
case FD_CONNECT:
TraceMsgA(“connection to server\n“);
break;
case FD_READ:
err = recv((SOCKET)wParam buf 100 0);
if (err > 0) {
TraceMsgA(“recv: %s\n“ buf);
}
else if (err == 0) {
closesocket((SOCKET)wParam);
TraceMsgA(“connection closed\n“);
}
else {
closesocket((SOCKET)wParam);
TraceMsgA(“recv failed GLE: %d\n“ WSAGetLastError());
}
break;
case FD_WRITE:
break;
case FD_CLOSE:
closesocket((SOCKET)wParam);
TraceMsgA(“connection closed\n“);
break;
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd message wParam lParam);
}
return 0;
}
void InitWindow(HINSTANCE hInstance) {
WCHAR szWindowClass[100] = L“Test“;
WNDCLASSEX wcex = { sizeof(WNDCLASSEX) };
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.lpszClassName = szWindowClass;
RegisterClassExW(&wcex);
g_hwnd = CreateWindowW(szWindowClass L“client“ WS_OVERLAPPEDWINDOW
CW_USEDEFAULT 0 CW_USEDEFAULT 0 nullptr nullptr hInstance nullptr);
if (g_hwnd) {
ShowWindow(g_hwnd SW_SHOW);
UpdateWindow(g_hwnd);
}
}
int APIENTRY wWinMain(_In_ HINSTANCE hInstance
_In_opt_ HINSTANCE hPrevInstance
_In_ LPWSTR lpCmdLine
_In_ int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
InitWindow(hInstance);
WSADATA wsaData;
WORD wVersionRequested = MAKEWORD
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-12-12 16:16 async_select_client\
文件 1471 2017-12-12 11:52 async_select_client\async_select_client.sln
目录 0 2017-12-12 16:16 async_select_client\async_select_client\
文件 8016 2017-12-12 15:28 async_select_client\async_select_client\async_select_client.cpp
文件 80 2017-12-12 11:52 async_select_client\async_select_client\async_select_client.h
文件 46227 2017-11-20 10:10 async_select_client\async_select_client\async_select_client.ico
文件 6714 2017-12-12 11:52 async_select_client\async_select_client\async_select_client.rc
文件 8341 2017-12-12 15:04 async_select_client\async_select_client\async_select_client.vcxproj
文件 1812 2017-12-12 11:52 async_select_client\async_select_client\async_select_client.vcxproj.filters
文件 165 2017-12-12 15:03 async_select_client\async_select_client\async_select_client.vcxproj.user
文件 1500 2017-12-12 11:52 async_select_client\async_select_client\resource.h
文件 46227 2017-11-20 10:10 async_select_client\async_select_client\small.ico
文件 340 2017-12-12 11:52 async_select_client\async_select_client\stdafx.cpp
文件 690 2017-12-12 11:52 async_select_client\async_select_client\stdafx.h
文件 370 2017-12-12 11:52 async_select_client\async_select_client\targetver.h
目录 0 2017-12-12 16:16 async_select_srv\
文件 1462 2017-12-12 11:27 async_select_srv\async_select_srv.sln
目录 0 2017-12-12 16:16 async_select_srv\async_select_srv\
文件 9528 2017-12-12 15:24 async_select_srv\async_select_srv\async_select_srv.cpp
文件 80 2017-12-12 11:27 async_select_srv\async_select_srv\async_select_srv.h
文件 46227 2017-11-20 10:10 async_select_srv\async_select_srv\async_select_srv.ico
文件 6660 2017-12-12 11:27 async_select_srv\async_select_srv\async_select_srv.rc
文件 8326 2017-12-12 14:37 async_select_srv\async_select_srv\async_select_srv.vcxproj
文件 1800 2017-12-12 11:27 async_select_srv\async_select_srv\async_select_srv.vcxproj.filters
文件 1476 2017-12-12 11:27 async_select_srv\async_select_srv\resource.h
文件 46227 2017-11-20 10:10 async_select_srv\async_select_srv\small.ico
文件 334 2017-12-12 11:27 async_select_srv\async_select_srv\stdafx.cpp
文件 690 2017-12-12 11:27 async_select_srv\async_select_srv\stdafx.h
文件 370 2017-12-12 11:27 async_select_srv\async_select_srv\targetver.h
- 上一篇:现场审计实施系统AO2011
- 下一篇:MAX电池电量检测芯片
相关资源
- socket连接传送数据,控制家电led
- tcl socket 编程
- socket tcp 转发工具
- WebSocket Demo
- TSocket.zip
- socket.zip
- sgcWebSockets_D7 实现WebSockets
- SocketTool.exe工具
- Socket源码Demo
- Socket工具SocketTool
- 客户端服务器端TCP/IP通信控件源代码
- qwebsocket使用wss连接工程源码,qt5.7d
- django+channels 2.0实现websocket
- libwebsocket VS2008编译的动态库静态库
- 仿QQ VS2010聊天程序服务器端、客户端
- UNIX Network Programming Volume 1 3rd (The S
- SocketTool.exe
- websocket_客户端
- 易语言Socket5客户端连接源码
- [ESP8266 ]WIFISocket_PCB电路图
- Rfid通信-网口模式
- WebSocket 服务端 封装 解析 16进制 字符
- zeromq-4.0.3.tar
- jmeter+websocket接口测试所需插件集合
- Unix Network Programming Volume 1Third Edition
- Delphi中TServerSocket和TClientSocket两个组件
- 在MQL中操作socket套接字
- sokit_socket调试工具
- Client客户端
- websocket-sharp.dll
评论
共有 条评论