Visual C++通信编程工程实例精解(附盘)
源代码在线查看: d089.bmp.txt
BOOL m_bAccept;
同样,在CLanSocketServer中添加事件处理函数、成员函数和成员变量:
public:
public:
virtual void OnAccept(int nErrorCode);
//} }AFX_VIRTUAL
//Implementation
public:
void CloseServer(void);
void SetMessagePara(CWnd*pParent, UINT m_nMessageID);
CString GetMessStr(void);
BOOL SendStr(CString m_str);
protected:
CWnd *m_pWnd;
UINT m_UserMsg;
CLanSocket *m_pSocket;
CString m_MessStr;
在ClanSocketClient中也需要添加事件处理函数、成员函数和成员变量:
public:
void SetMessagePara(CWnd* pParent, UINT m_nMessageID);
void Rest(void);
CString GetMessStr(void);
BOOL SendStr(CString m_str);
BOOL IsConnect(void);
public:
virtual void OnConnect(int nErrorCode);
virtual void OnReceive(int nErrorCode);
virtual void OnSend(int nErrorCode);
virtual void OnClose(int nErrorCode);
//Implementation
protected:
CWnd * m_pWnd;
UINT m_UserMsg;
BOOLm_bConnected;,/是否连接
charm_szBuffer[4096l;,/消息缓冲区
CString m_MessStr;
(6)编写函数内容
在每个类的构造函数和析构函数中添加函数声明,代码如下:
CLanSocket::CLanSocket0
{
m_bAccept = FALSE;
}