📄 clientsocket.cpp
字号:
// ClientSocket.cpp : implementation file
//
#include "stdafx.h"
#include "ChatServer.h"
#include "ClientSocket.h"
#include "msg.h"
#include "ChatServerDoc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CClientSocket
IMPLEMENT_DYNAMIC(CClientSocket, CSocket)
CClientSocket::CClientSocket()
{
}
CClientSocket::~CClientSocket()
{
if (m_pArchiveOut != NULL)
delete m_pArchiveOut;
if (m_pArchiveIn != NULL)
delete m_pArchiveIn;
if (m_pFile != NULL)
delete m_pFile;
}
// Do not edit the following lines, which are needed by ClassWizard.
#if 0
BEGIN_MESSAGE_MAP(CClientSocket, CSocket)
//{{AFX_MSG_MAP(CClientSocket)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
#endif // 0
/////////////////////////////////////////////////////////////////////////////
// CClientSocket member functions
CClientSocket::CClientSocket(CChatServerDoc* pDoc)
{
m_pDoc = pDoc;
m_nMsgCount = 0;
m_pFile = NULL;
m_pArchiveIn = NULL;
m_pArchiveOut = NULL;
}
void CClientSocket::Init()
{
m_pFile = new CSocketFile(this);
m_pArchiveIn = new CArchive(m_pFile,CArchive::load);
m_pArchiveOut = new CArchive(m_pFile,CArchive::store);
}
void CClientSocket::SendMsg(CMsg* pMsg)
{
if (m_pArchiveOut != NULL)
{
//数据由pMsg输出到m_pArchiveOut
pMsg->Serialize(*m_pArchiveOut);
//将数据写入文件
m_pArchiveOut->Flush();
}
}
void CClientSocket::ReceiveMsg(CMsg* pMsg)
{
//数据由m_pArchiveIn读入到pMsg
pMsg->Serialize(*m_pArchiveIn);
}
void CClientSocket::OnReceive(int nErrorCode)
{
//调用CSocekt的OnReceive函数
CSocket::OnReceive(nErrorCode);
//其余工作交给文档类处理
m_pDoc->ProcessReceive(this);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -