📄 clientsocket.cpp
字号:
// ClientSocket.cpp : implementation file
//
#include "stdafx.h"
#include "Client.h"
#include "ClientSocket.h"
#include "Msg.h"
#include "ClientDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CClientSocket
CClientSocket::CClientSocket()
{
m_pArchiveIn = NULL;
m_pArchiveOut = NULL;
m_pSocketFile = NULL;
m_bClose = FALSE;
}
CClientSocket::~CClientSocket()
{
if(m_pArchiveIn)
delete m_pArchiveIn;
if(m_pArchiveOut)
delete m_pArchiveOut;
if(m_pSocketFile)
delete m_pSocketFile;
m_pArchiveIn = NULL;
m_pArchiveOut = NULL;
m_pSocketFile = NULL;
m_bClose = TRUE;
}
// 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
void CClientSocket::Init(CClientDlg *pDlg)
{
m_pSocketFile = new CSocketFile(this);
m_pArchiveIn = new CArchive(m_pSocketFile, CArchive::load);
m_pArchiveOut = new CArchive(m_pSocketFile, CArchive::store);
m_bClose = FALSE;
m_pDlg = pDlg;
}
void CClientSocket::OnReceive(int nErrorCode)
{
do
{
CMsg msg;
msg.Serialize(*m_pArchiveIn);
m_pDlg->UpdateData(TRUE);
m_pDlg->m_strShow += "\r\n";
m_pDlg->m_strShow += msg.m_strMsg;
m_pDlg->UpdateData(FALSE);
m_pDlg->m_Show.LineScroll(m_pDlg->m_Show.GetLineCount());
}
while (!m_pArchiveIn->IsBufferEmpty());
CSocket::OnReceive(nErrorCode);
}
void CClientSocket::SendMsg(CMsg * pMsg)
{
if (m_pArchiveOut != NULL)
{
pMsg->Serialize(*m_pArchiveOut);
m_pArchiveOut->Flush();
}
}
void CClientSocket::OnClose(int nErrorCode)
{
m_bClose = TRUE;
CSocket::OnClose(nErrorCode);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -