📄 clientsocket.cpp
字号:
// ClientSocket.cpp : implementation file
//
#include "stdafx.h"
#include "DataProvider.h"
#include "ClientSocket.h"
#include "DataProviderDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CClientSocket
CClientSocket::CClientSocket()
{
m_pFile = NULL;
m_pArchiveIn = NULL;
m_pArchiveOut = NULL;
m_bNetConnected = FALSE;
}
CClientSocket::~CClientSocket()
{
if(m_pArchiveIn) delete m_pArchiveIn;
if(m_pArchiveOut) delete m_pArchiveOut;
if(m_pFile) delete m_pFile;
}
// 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(CDataProviderDlg* m_pParentWnd)
{
m_pView = m_pParentWnd;
if(m_pArchiveIn) delete m_pArchiveIn;
if(m_pArchiveOut) delete m_pArchiveOut;
if(m_pFile) delete m_pFile;
m_pFile = new CSocketFile(this);
m_pArchiveOut = new CArchive(m_pFile,CArchive::store);
m_pArchiveIn = new CArchive(m_pFile,CArchive::load);
}
void CClientSocket::OnClose(int nErrorCode)
{
// TODO: Add your specialized code here and/or call the base class
CSocket::OnClose(nErrorCode);
m_bNetConnected=FALSE;
}
void CClientSocket::OnReceive(int nErrorCode)
{
// TODO: Add your specialized code here and/or call the base class
LPMODFRAME lpreceive;
LPSTR lpTemp;
UINT nLong;
do
{
lpreceive = new ModFrame;
*m_pArchiveIn >> lpreceive->nOrder;
*m_pArchiveIn >> nLong;
lpTemp = lpreceive->Content.GetBuffer(nLong + 1);
m_pArchiveIn->Read(lpTemp,nLong);
lpTemp[nLong]= 0;
lpreceive->Content.ReleaseBuffer(-1);
m_pView->HandleNetData(lpreceive);
}
while(!m_pArchiveIn->IsBufferEmpty());
CSocket::OnReceive(nErrorCode);
}
void CClientSocket::SendFrame(LPMODFRAME lpSend)
{
LPSTR lpTemp;
UINT nLong = lpSend->Content.GetLength();
*m_pArchiveOut << lpSend->nOrder;
*m_pArchiveOut << nLong;
lpTemp = lpSend->Content.LockBuffer();
m_pArchiveOut->Write(lpTemp,nLong);
lpSend->Content.ReleaseBuffer();
m_pArchiveOut->Flush();
CListBox* m_MessageList=(CListBox*)
m_pView->GetDlgItem(IDC_SENT_DATA);
if (m_MessageList->GetCount()>30)
m_MessageList->ResetContent();
m_MessageList->AddString(lpSend->Content);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -