www.pudn.com > 数字硬盘录像机软件代码.rar > CLIENTSOCK.CPP


// clntsock.cpp : implementation of the CClientSocket class 
 
#include "stdafx.h" 
#include "GtMpeg.h" 
#include "GtMpegWnd.h" 
#include "ClientSock.h" 
#include "CommandMsg.h" 
#include "DataMsg.h" 
///////////////////////////////////////////////////////////////////////////// 
// 
///////////////////////////////////////////////////////////////////////////// 
IMPLEMENT_DYNAMIC(CClientSocket, CSocket) 
///////////////////////////////////////////////////////////////////////////// 
// 
///////////////////////////////////////////////////////////////////////////// 
CClientSocket::CClientSocket() 
{ 
	m_pFile = NULL; 
	m_pArchiveIn = NULL; 
	m_pArchiveOut = NULL; 
	m_sClientIP=_T(""); 
 
} 
///////////////////////////////////////////////////////////////////////////// 
// 
///////////////////////////////////////////////////////////////////////////// 
void CClientSocket::Init() 
{ 
	m_pFile = new CSocketFile(this); 
	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::SendMsg(CDataMsg* pMsg) 
{ 
	if (m_pArchiveOut != NULL) 
	{ 
		pMsg->Serialize(*m_pArchiveOut); 
		m_pArchiveOut->Flush(); 
	} 
} 
///////////////////////////////////////////////////////////////////////////// 
// 
///////////////////////////////////////////////////////////////////////////// 
void CClientSocket::ReceiveMsg(CCommandMsg* pMsg) 
{ 
	pMsg->Serialize(*m_pArchiveIn); 
} 
///////////////////////////////////////////////////////////////////////////// 
// 
///////////////////////////////////////////////////////////////////////////// 
void CClientSocket::OnReceive(int nErrorCode) 
{ 
	CSocket::OnReceive(nErrorCode); 
	CGtMpegWnd * pWnd=(CGtMpegWnd *)theApp.m_pMainWnd; 
	pWnd->ProcessPendingRead(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 //_DEBUG 
///////////////////////////////////////////////////////////////////////////// 
// 
///////////////////////////////////////////////////////////////////////////// 
CString  CClientSocket::GetClientIP() 
{ 
	   CString sClientIP; 
	   UINT nPort; 
	   GetPeerName(sClientIP,nPort);  
	   return sClientIP; 
}