?? clientsocket.cpp
字號:
// ClientSocket.cpp: implementation of the CClientSocket class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "ChatServer.h"
#include "ServerDlg.h"
#include "ClientSocket.h"
#include "msg.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
//構造函數
CClientSocket::CClientSocket(CServerDlg* pDlg)
{
m_pDlg=pDlg;
m_nMsgCount=0;
m_pFile=NULL;
m_pArchiveIn=NULL;
m_pArchiveOut=NULL;
}
//初始化
void CClientSocket::Initialize()
{
//構造相應的CSocketFile對象
m_pFile=new CSocketFile(this);
//構造相應的CArchive對象
m_pArchiveIn=new CArchive(m_pFile,CArchive::load);
m_pArchiveOut=new CArchive(m_pFile,CArchive::store);
}
//放棄傳送
void CClientSocket::Abort()
{
if (m_pArchiveOut!=NULL)
{
m_pArchiveOut->Abort();
delete m_pArchiveOut;
m_pArchiveOut=NULL;
}
}
//發送消息
void CClientSocket::SendMessage(CMsg* pMsg)
{
if (m_pArchiveOut!=NULL)
{
//對消息進行序列化
pMsg->Serialize(*m_pArchiveOut);
//將CArchive對象中的數據強制性寫入文件中
m_pArchiveOut->Flush();
}
}
//接收消息
void CClientSocket::ReceiveMessage(CMsg* pMsg)
{
//對消息進行序列化
pMsg->Serialize(*m_pArchiveIn);
}
//OnReceive事件處理函數
void CClientSocket::OnReceive(int nErrorCode)
{
CSocket::OnReceive(nErrorCode);
//調用主對話框類中的相應函數處理
m_pDlg->OnReceive(this);
}
//析構函數
CClientSocket::~CClientSocket()
{
if (m_pArchiveOut!=NULL)
delete m_pArchiveOut;
if (m_pArchiveIn!=NULL)
delete m_pArchiveIn;
if (m_pFile!=NULL)
delete m_pFile;
}
#ifdef _DEBUG
void CClientSocket::AssertValid() const
{
CSocket::AssertValid();
}
void CClientSocket::Dump(CDumpContext& dc) const
{
CSocket::Dump(dc);
}
#endif
IMPLEMENT_DYNAMIC(CClientSocket,CSocket)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -