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

📄 clientsocket.cpp

📁 关于使用VC编程的代码
💻 CPP
字号:
// ClientSocket.cpp : implementation file
//

#include "stdafx.h"
#include "MyChatSvr.h"
#include "ClientSocket.h"
#include "MyChatSvrDoc.h"

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

/////////////////////////////////////////////////////////////////////////////
// CClientSocket
CClientSocket::CClientSocket()
{
	m_pDoc = NULL;
}

CClientSocket::CClientSocket(CMyChatSvrDoc* pDoc)
{
	m_pDoc = pDoc;
}


CClientSocket::~CClientSocket()
{
	if(m_pArIn != NULL)
	{
		m_pArIn->Close();
		delete m_pArIn;
		m_pArIn = NULL;
	}
	if(m_pArOut != NULL)
	{
		m_pArOut->Close();
		delete m_pArOut;
		m_pArOut = NULL;
	}
	if(m_pFile != NULL)
	{
		m_pFile->Close();
		delete m_pFile;
		m_pFile = NULL;
	}
}


// 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::OnReceive(int nErrorCode) 
{
	CSocket::OnReceive(nErrorCode);

//	AfxMessageBox("svr:enter ClientSocket::OnReceive()");
	ASSERT(m_pDoc != NULL);
	m_pDoc->ProcessReceive(this);	
}

void CClientSocket::Init()
{
	m_pFile = new CSocketFile(this);
	m_pArIn = new CArchive(m_pFile, CArchive::load);
	m_pArOut = new CArchive(m_pFile, CArchive::store);
//	Listen();
}

CString CClientSocket::ReadData()
{
//	AfxMessageBox("svr:enter ClientSocket::readdata()");
	CString str;
	*m_pArIn >> str;
	return str;
}

void CClientSocket::SendData(CString strMsg)
{
	*m_pArOut << "Server: " + strMsg;
	m_pArOut->Flush();
}

void CClientSocket::Finish_Comm()
{
	if(m_pArIn != NULL)
	{
		m_pArIn->Close();
		delete m_pArIn;
		m_pArIn = NULL;
	}
	if(m_pArOut != NULL)
	{
		m_pArOut->Close();
		delete m_pArOut;
		m_pArOut = NULL;
	}
	if(m_pFile != NULL)
	{
		m_pFile->Close();
		delete m_pFile;
		m_pFile = NULL;
	}
	Close();
}

⌨️ 快捷键说明

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