⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clientsocket.cpp

📁 Visual_C++.NET精彩案例237.rar
💻 CPP
字号:
// ClientSocket.cpp : 实现文件
//

#include "stdafx.h"
#include "NetClient.h"
#include "ClientSocket.h"
#include "msg.h"
#include "netclientview.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


// CClientSocket

CClientSocket::CClientSocket(CNetClientView* pView)
{
	m_pView=pView;
	m_pFile=NULL;
	m_pArchiveIn=NULL;
	m_pArchiveOut=NULL;
}

CClientSocket::~CClientSocket()
{
	if (m_pArchiveOut != NULL)
		delete m_pArchiveOut;

	if (m_pArchiveIn != NULL)
		delete m_pArchiveIn;

	if (m_pFile != NULL)
		delete m_pFile;
}


#if 0
BEGIN_MESSAGE_MAP(CClientSocket, CSocket)
	//{{AFX_MSG_MAP(CClientSocket)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()
#endif	// 0


// CClientSocket 成员函数

void CClientSocket::OnReceive(int nErrorCode) 
{
	// TODO: 在此添加代码
	m_pView->ReceiveFile(this);
	CSocket::OnReceive(nErrorCode);
}

void CClientSocket::OnConnect(int nErrorCode) 
{
	// TODO: 在此添加代码
//	m_pView->ReceiveFile(this);
	CSocket::OnConnect(nErrorCode);
}

void CClientSocket::Initialize()
{
	m_pFile=new CSocketFile(this);
	m_pArchiveIn = new CArchive(m_pFile,CArchive::load);
	m_pArchiveOut = new CArchive(m_pFile,CArchive::store);
}




BOOL CClientSocket::SendMsg(CMsg *pMsg)
{
	if(!m_pArchiveOut==NULL)
	{
		pMsg->Serialize(*m_pArchiveOut);
		m_pArchiveOut->Flush();
		return TRUE;
	}
	return FALSE;
}

BOOL CClientSocket::ReceiveMsg(CMsg *pMsg)
{
	if(!m_pArchiveIn==NULL)
	{
		pMsg->Serialize(*m_pArchiveIn);
		return TRUE;
	}
	return FALSE;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -