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

📄 testclient.cpp

📁 异步网络通讯例程
💻 CPP
字号:
// TestClient.cpp: implementation of the CTestClient class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "SyncClient.h"
#include "TestClient.h"
#include "iostream"
using namespace std;

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

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CTestClient::CTestClient(SOCKET s, const char* pszPeerAddr, unsigned short nPeerPort, BOOL bCloseWait /* = TRUE */ )
 : CSyncSocketWorker<CTestClient>(s, pszPeerAddr, nPeerPort, bCloseWait)
{
	
}

CTestClient::~CTestClient()
{
}

extern CRITICAL_SECTION g_cs;

void CTestClient::ProcessData()
{
 	const int nBufferSize = 8192;
	char szBuffer[nBufferSize];

	CFile file;
	file.Open(TEXT("recv.jpg"), CFile::modeCreate | CFile::modeWrite);
	int nRead;

	DWORD dwStart = GetTickCount();
	while(nRead = Read(szBuffer, nBufferSize))
	{
		file.Write(szBuffer, nRead);
		if(IsShutingdown())
		{
			cout << "shuting down" << endl;
			break;
		}
	}

	cout << "Speed = " << double(file.GetLength()) / (double(GetTickCount() - dwStart) / 1000.0) / 1024 << "KB/s" << endl;
	file.Close();
}

⌨️ 快捷键说明

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