将服务端select设置为非阻塞,处理更多业务
服务端代码: #include<WinSock2.h> #include<Windows.h> #include<vector> #include<stdio.h> #include<iostream> #pragma comment(lib,"ws2_32.lib") enum CMD { CMD_Login, CMD_Login_Result, CMD_Logout, CMD_Logout_Result, CMD_ERROR }; //包头 struct DataHeader { short dataLength; short cmd; }; //包体 struct Login:public DataHeader { Login() { dataLength = sizeof(Login); cmd = CMD_Login; } char username[32]; char password[32]; }; struct LoginResult :public DataHeader { LoginResult() { dataLength = sizeof(LoginResult); cmd = CMD_Login_Result; result = 0; } int result; }; struct Logout :public DataHeader { Logout()