📄 acceptsocket.cpp
字号:
// AcceptSocket.cpp : implementation file
//
#include "stdafx.h"
#include "MsgServer.h"
#include "ListenSocket.h"
#include "AcceptSocket.h"
#include "MsgServerDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAcceptSocket
CAcceptSocket::CAcceptSocket( CMsgServerDlg *pMsgServerDlg )
{
m_pMsgServerDlg = pMsgServerDlg;
}
CAcceptSocket::~CAcceptSocket()
{
}
// Do not edit the following lines, which are needed by ClassWizard.
#if 0
BEGIN_MESSAGE_MAP(CAcceptSocket, CSocket)
//{{AFX_MSG_MAP(CAcceptSocket)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
#endif // 0
/////////////////////////////////////////////////////////////////////////////
// CAcceptSocket member functions
void CAcceptSocket::OnReceive(int nErrorCode)
{
CMsgServerDlg* pDlg=(CMsgServerDlg*)::AfxGetMainWnd();
char strCmdMsg[520];
char strRevMsg[520];
int ByteCount;
int EndFlag=0;
strcpy(strCmdMsg,"");
do
{
strcpy(strRevMsg,"");
ByteCount=Receive(strRevMsg,520);
if(ByteCount>520 || ByteCount<=0)
{
AfxMessageBox("接收数据出错",MB_OK);
return;
}
else if(ByteCount<520 && ByteCount>0)
{
EndFlag=1;
}
strRevMsg[ByteCount]=0;
strcat(strCmdMsg,strRevMsg);
}while(EndFlag==0);
if(strstr(strCmdMsg,"GET_MSG"))
{
if ( pDlg->SendBuffer->iCurrentMsgCount<=0 || pDlg->SendBuffer->iCurrentMsgCount>10)
{
CString temp="NO_DATA";
Send( temp,strlen(temp),0);
}
else
{
int k=Send(pDlg->SendBuffer,pDlg->iDataSize,0);
}
}
else if(strstr(strCmdMsg,"<SET_MSG>"))
{
CString strRevMsg;
strRevMsg.Format("%s",strCmdMsg);
strRevMsg = strRevMsg.Right(strlen(strRevMsg)-9);
pDlg->AddMsgToList(strRevMsg);
}
m_pMsgServerDlg->m_pAcceptList.RemoveTail();
Close();
CSocket::OnReceive(nErrorCode);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -