C++之WSAAsyncSelect模型实例(2)
复制代码 代码如下: #include afxwin.h #include afxext.h //CStatusBar #include WinSock2.h #include afxcmn.h #pragma comment(lib, "WS2_32.lib") #define MAX_SOCKET 56 //最大客户量 class CMyAp
复制代码 代码如下:
#include <afxwin.h>
#include <afxext.h> //CStatusBar
#include <WinSock2.h>
#include <afxcmn.h>
#pragma comment(lib, "WS2_32.lib")
#define MAX_SOCKET 56 //最大客户量
class CMyApp:public CWinApp
{
public:
BOOL InitInstance();
};
//CMainDialog
class CMainDialog:public CDialog
{
public:
CMainDialog(CWnd* pParentWnd=NULL);
protected:
virtual BOOL OnInitDialog();
virtual void OnCancel();
//开启或停止服务
afx_msg void OnStart();
afx_msg void OnClear();
afx_msg long OnSocket(WPARAM wParam, LPARAM lParam);
BOOL CreateAndListen(int nPort);
//向客户连接列表中加一个客户
BOOL AddClient(SOCKET s);
//从客户连接列表中移除一个客户
void RemoveClient(SOCKET s);
//关闭所有连接
void CloseAllSocket();
protected:
SOCKET m_socket;
//两个子窗口控件
CListBox m_listInfo;
CStatusBarCtrl m_bar;
//客户连接列表
SOCKET m_arClient[MAX_SOCKET]; //套接字列表
int m_nClient; //上述数组的大小
DECLARE_MESSAGE_MAP()
};
#include <afxext.h> //CStatusBar
#include <WinSock2.h>
#include <afxcmn.h>
#pragma comment(lib, "WS2_32.lib")
#define MAX_SOCKET 56 //最大客户量
class CMyApp:public CWinApp
{
public:
BOOL InitInstance();
};
//CMainDialog
class CMainDialog:public CDialog
{
public:
CMainDialog(CWnd* pParentWnd=NULL);
protected:
virtual BOOL OnInitDialog();
virtual void OnCancel();
//开启或停止服务
afx_msg void OnStart();
afx_msg void OnClear();
afx_msg long OnSocket(WPARAM wParam, LPARAM lParam);
BOOL CreateAndListen(int nPort);
//向客户连接列表中加一个客户
BOOL AddClient(SOCKET s);
//从客户连接列表中移除一个客户
void RemoveClient(SOCKET s);
//关闭所有连接
void CloseAllSocket();
protected:
SOCKET m_socket;
//两个子窗口控件
CListBox m_listInfo;
CStatusBarCtrl m_bar;
//客户连接列表
SOCKET m_arClient[MAX_SOCKET]; //套接字列表
int m_nClient; //上述数组的大小
DECLARE_MESSAGE_MAP()
};
TCPClient.cpp源文件如下:
收藏文章
精彩图集
精彩文章