📄 chatsocket.cpp
字号:
// ChatSocket.cpp : implementation file
//
#include "stdafx.h"
#include "Server.h"
#include "ChatSocket.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CChatSocket
CChatSocket::CChatSocket()
{
}
CChatSocket::~CChatSocket()
{
}
// Do not edit the following lines, which are needed by ClassWizard.
#if 0
BEGIN_MESSAGE_MAP(CChatSocket, CSocket)
//{{AFX_MSG_MAP(CChatSocket)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
#endif // 0
/////////////////////////////////////////////////////////////////////////////
// CChatSocket member functions
CChatSocket::CChatSocket(CServerDlg *psdlg)
{
m_psdlg=psdlg;
inited=false;
}
void CChatSocket::OnReceive(int nErrorCode)//通知套节字缓冲区存在可读入的数据
{
CSocket::OnReceive(nErrorCode);
m_psdlg->readall(this);
}
void CChatSocket::AssertValid() const
{
CSocket::AssertValid();
}
void CChatSocket::sendmsg(CMsg &msg)//发送数据
{
if (m_pout != NULL)
{
msg.Serialize(*m_pout);
m_pout->Flush();
}
}
void CChatSocket::receivemsg(CMsg &msg)//接收数据
{
msg.Serialize(*m_pin);
if(msg.msgtype==MSG_CTS_newclient)
msg.from=seq;
}
void CChatSocket::OnClose(int nErrorCode)
{
// TODO: Add your specialized code here and/or call the base class
CSocket::OnClose(nErrorCode);
}
void CChatSocket::Init() //初始化文件对象
{
m_pfile = new CSocketFile(this);//创建一个与CSocketFile相联系的CArchive对象以进行数据的发送和接收。m_pfile代表套节字文件对象
m_pin = new CArchive(m_pfile,CArchive::load);//载入(接收),m_pin代表套节字归档对象
m_pout = new CArchive(m_pfile,CArchive::store);//存储(发送),m_pout代表套节字归档对象
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -