📄 clientsocket.cpp
字号:
//AcceptSocket.cpp : implementation file
//
#include "stdafx.h"
#include "ServerMFC.h"
#include "AcceptSocket.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAcceptSocket
CAcceptSocket::CAcceptSocket(CMainFrame *pMainFrame)
{
m_pMainFrame=pMainFrame;
}
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)
{
// TODO: Add your specialized code here and/or call the base class
//以下为加入的代码
// m_pMainFrame->FetchMsg(this);
//以上为加入的代码
char pMsg[10000],tempMsg[1000];
int ByteCount;
int EndFlag=0;
char AnswerMsg[10100];
strcpy(pMsg,"");
do
{
strcpy(tempMsg,"");
ByteCount=Receive(tempMsg,1000);
if(ByteCount>1000 || ByteCount<=0)
{
AfxMessageBox("接收数据出错",MB_OK);
return;
}
else
if(ByteCount<1000 && ByteCount>0)
{
EndFlag=1;
}
tempMsg[ByteCount]=0;
strcat(pMsg,tempMsg);
}while(EndFlag==0);
AfxMessageBox(pMsg,MB_OK);
sprintf(AnswerMsg,"我已经收到你的消息\n\"%s\"\n谢谢",pMsg);
//SendMsg(pAcceptSocket,AnswerMsg);
Send(AnswerMsg,strlen(AnswerMsg),0);
CSocket::OnReceive(nErrorCode);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -