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

📄 connectsock.cpp

📁 简单的远程控制工具,分为服务器与客户斋,让你了解socket编程的知识.
💻 CPP
字号:
// ConnectSock.cpp : implementation file
//

#include "stdafx.h"
#include "ConnectSock.h"
#include "msg.h"

#include "MainFrm.h"

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

/////////////////////////////////////////////////////////////////////////////
// CConnectSock

CConnectSock::CConnectSock(CMainFrame* pWnd)
{
	m_pWnd = pWnd;
	m_nMsgCount = 0;
	m_pFile = NULL;
	m_pArchiveIn = NULL;
	m_pArchiveOut = NULL;
}

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

	if (m_pArchiveIn != NULL)
		delete m_pArchiveIn;

	if (m_pFile != NULL)
		delete m_pFile;
}

/////////////////////////////////////////////////////////////////////////////
// CConnectSock Operations

void CConnectSock::Init()
{
	m_pFile = new CSocketFile(this);
	if (m_pFile != NULL)
	{
	  m_pArchiveIn = new CArchive(m_pFile,CArchive::load,4096 * 250);
	  m_pArchiveOut = new CArchive(m_pFile,CArchive::store,4096 * 250);
	}
}

void CConnectSock::Abort()
{
	if (m_pArchiveOut != NULL)
	{
		m_pArchiveOut->Abort();
		delete m_pArchiveOut;
		m_pArchiveOut = NULL;
	}
}

void CConnectSock::SendMsg(CMsg* pMsg)
{
    if (pMsg == NULL) return;
	if (m_pArchiveOut != NULL)
	{
		pMsg->Serialize(*m_pArchiveOut);
		m_pArchiveOut->Flush();
	}
}

void CConnectSock::ReceiveMsg(CMsg* pMsg)
{
    if (pMsg == NULL) return ;
	pMsg->Serialize(*m_pArchiveIn);
//	m_pArchiveIn->Flush ();
//	m_pFile->Flush ();
	
}

#ifdef _DEBUG
void CConnectSock::AssertValid() const
{
	CSocket::AssertValid();
}

void CConnectSock::Dump(CDumpContext& dc) const
{
	CSocket::Dump(dc);
}
#endif //_DEBUG

IMPLEMENT_DYNAMIC(CConnectSock, CSocket)

// Do not edit the following lines, which are needed by ClassWizard.
#if 0
BEGIN_MESSAGE_MAP(CConnectSock, CSocket)
	//{{AFX_MSG_MAP(CConnectSock)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()
#endif	// 0

/////////////////////////////////////////////////////////////////////////////
// CConnectSock member functions

void CConnectSock::OnReceive(int nErrorCode) 
{
	// TODO: Add your specialized code here and/or call the base class
	CSocket::OnReceive(nErrorCode);
	m_pWnd->ProcessPendRead(this);

}


void CConnectSock::Del_Archive()
{
	if (m_pArchiveOut != NULL)
		delete m_pArchiveOut;

	if (m_pArchiveIn != NULL)
		delete m_pArchiveIn;

	if (m_pFile != NULL)
		delete m_pFile;
}

⌨️ 快捷键说明

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