Introduction
Client
Just derive a child CTestClient
class from CSyncSocketWorker
and override its virtual function ProcessData
.
void CTestClient::ProcessData()
{
const int nBufferSize = 8192;
char szBuffer[nBufferSize];
CFile file;
file.Open(TEXT("recv.dat"), 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();
}
Server
Same as client.
void CEchoWorker::ProcessData()
{
const int nBufferSize = 4096;
char* pBuffer = new char[nBufferSize];
if(!pBuffer)
return;
CFile file;
file.Open(TEXT("testfile.dat"), CFile::modeRead);
while(!IsShutingdown() && IsConnected())
{
int nRead = file.Read(pBuffer, nBufferSize);
if(nRead == 0)
break;
Write(pBuffer, nRead, FALSE);
}
SendRightNow();
while(!IsSendBufferEmpty() && IsConnected())
Sleep(500);
delete [] pBuffer;
}
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.