📄 client.cpp
字号:
// lient.cpp : implementation file
//
#include "stdafx.h"
#include "NClient.h"
#include "Client.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
class CNServerApp;
/////////////////////////////////////////////////////////////////////////////
// Client
Cclient::Cclient()
{
}
Cclient::~Cclient()
{
}
void Cclient::OnReceive( int nErrorCode )
{
CSocket::OnReceive(nErrorCode);
char pBuf[2049];
// for(int i=0;i<2049;i++) pBuf[i] = 0;
int nLen = this->Receive(pBuf,2048,0);
pBuf[nLen] = 0;
for(int i=0;i<nLen;i++){
pBuf[i] -= 10;
}
CString tempstr = "";
tempstr = (CString)pBuf;
DataOperation(tempstr);
}
bool Cclient::SendData(CString strData)
{
int nLen = strlen(strData);
if( nLen<= 0)
return true;
char pBuf[2049];
// for(int i;i<2048;i++)pBuf[2048] = 0;
pBuf[nLen] = 0;
strcpy(pBuf,strData);
for(int i=0;i<nLen;i++){
pBuf[i] += 10;
}
this->Send(pBuf,nLen,0);
Sleep(10);
return true;
}
void Cclient::DataOperation(CString strData)
{
int thisLen = strlen(strData);
if(thisLen <= 0) return;
CString strOper = "";
if(((CNClientApp *)AfxGetApp())->m_status == REQ_NEWUSER){
((CNClientApp *)AfxGetApp())->m_status = STA_NORMAL;
if(thisLen < 13)
return ;
strOper = strData.Left(11);
if(strcmp(strOper,"NewUserCode") == 0)
((CNClientApp *)AfxGetApp())->m_strLastMsg = strData;
return;
}
if(((CNClientApp *)AfxGetApp())->m_status == REQ_CHKUSER){
((CNClientApp *)AfxGetApp())->m_status = STA_NORMAL;
if(thisLen < 11)
return ;
strOper = strData;
if(strcmp(strOper,"CheckUserOk") == 0)
((CNClientApp *)AfxGetApp())->m_strLastMsg = strData;
return;
}
if(((CNClientApp *)AfxGetApp())->m_status == REQ_MODUSER){
((CNClientApp *)AfxGetApp())->m_status = STA_NORMAL;
if(thisLen < 9 )
return ;
strOper = strData;
if(strcmp(strOper,"ModUserOk") == 0)
((CNClientApp *)AfxGetApp())->m_strLastMsg = strData;
return;
}
if(((CNClientApp *)AfxGetApp())->m_status == REQ_GETREQ){
if(thisLen < 10 )
return ;
strOper = strData;
if(strcmp(strOper,"SendReqEnd") == 0)
((CNClientApp *)AfxGetApp())->m_status = STA_NORMAL;
else
((CNClientApp *)AfxGetApp())->AddLastMsg(strData);
return;
}
if(((CNClientApp *)AfxGetApp())->m_status == REQ_GETFILELIST){
if(thisLen < 11 )
return ;
strOper = strData;
if(strcmp(strOper,"FileListEnd") == 0)
((CNClientApp *)AfxGetApp())->m_status = STA_NORMAL;
else
((CNClientApp *)AfxGetApp())->AddLastMsg(strData);
return;
}
if(((CNClientApp *)AfxGetApp())->m_status == REQ_GETFILE){
strOper = strData;
if(strcmp(strOper,"EndSenFile") == 0)
((CNClientApp *)AfxGetApp())->m_status = STA_NORMAL;
else
((CNClientApp *)AfxGetApp())->WriteData(strData);
return;
}
}
// Do not edit the following lines, which are needed by ClassWizard.
#if 0
BEGIN_MESSAGE_MAP(Client, CSocket)
//{{AFX_MSG_MAP(Client)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
#endif // 0
/////////////////////////////////////////////////////////////////////////////
// Client member functions
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -