testclient.cpp

来自「异步网络通讯例程」· C++ 代码 · 共 56 行

CPP
56
字号
// 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 + =
减小字号Ctrl + -
显示快捷键?