📄 d117.bmp.txt
字号:
{
CChatClient 4 t=(CChatClient*)m_dlg->m_connectionList.GetNext(pos);
if(t->m_hSocketf =this->m_hSocket)
{
t->SendMessage(&temp);
)
)
)
)
while(!m_aSessionln->IsBufferEmpty(》;
)
12)添加CChatClient类关闭连接函数OnClose()。
void CChatClient::OnClose(int nErrorCode)
{
,,TODO: Add your specialized code here and/or call the base class
m_bClose=true;
CloseSocket();
m_dlg->CloseSessionSocket0;
CSocket::OnClose(nEnmCode);
}
在以上的Socket类中添加了所有的必要事件处理之后,已经构建出客户端和服务器端
的CSocket,此时,需要向对话框添加Socket类的变量对象。由于已经按照服务器和客户机
的功能需求不同建立了不同的Socket类,所以只用向对话框类(CLANChatDlg>中添加2
个套接字类的成员变量。
CChatClient m_ChatClient;
CChatServer m_pListenSocket;
在添加成员变量之前,还需要在LANChatDlg.h中引用必要的头文件:
#include "ChatServer.h"
#include "ChatClient.h"
在对话框类中的套接字的创建、侦听和连接都将在启动/连接服务器时实现。
(6)建立客户机与服务器之间的连接
打开ClassWizard,为启动按钮(1DC_START_LINK)的BN_CLICKED事件添加事件处
理函数,编辑该函数。上面提到的套接字的创建、侦听和连接都在这个函数内实现。
void CLANChatDlg::OnStartLink()
{
// TODO: Add your control notification handler code here
UpdateData0;
if( !m_Type )
{
if( !m_blnit)
//7
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -