⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clientsocket.cpp

📁 一个复杂的客户端程序
💻 CPP
字号:
// ClientSocket.cpp : implementation file
//

#include "stdafx.h"
#include "Client.h"
#include "ClientSocket.h"

//加入的代码
#include "MainFrm.h"
//加入的代码完毕

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CClientSocket

//加入代码
CClientSocket::CClientSocket(CMainFrame *pMainFrame)
{
	m_pMainFrame=pMainFrame;
}
//加入代码完毕

CClientSocket::~CClientSocket()
{
}


// 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::OnReceive(int nErrorCode) 
{
	// TODO: Add your specialized code here and/or call the base class
	
	char pMsg[10000],tempMsg[1000];
	int ByteCount;  //每次读取的字符个数
	int EndFlag=0;  //接收完毕的标志

	
	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);
	CSocket::OnReceive(nErrorCode);
}
//加入的代码完毕

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -