Click here to Skip to main content
15,886,731 members
Articles / Programming Languages / C++

Push Framework - A C++ toolkit for high performance server development

Rate me:
Please Sign up or sign in to vote.
4.96/5 (86 votes)
23 May 2012Apache15 min read 260.2K   26.9K   316  
Write asynchronous, multithreaded servers in a few lines of code. Monitor realtime activity with a deploy-only dashboard.
// QoSExampleClient.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include "MyQoSClient.h"
char hostAddress[] = "127.0.0.1";
unsigned int uPort = 2010;

#include "StopWatch.h"

int _tmain(int argc, _TCHAR* argv[])
{
	TCPSocket::initializeWinsock();


	CMyQoSClient client;

	cout << "Connecting " << std::endl;

	if (!client.connect(hostAddress, uPort))
	{
		cout << "Unable to connect " << std::endl;
	}
	cout << "Put Q or q to stop" << std::endl;
	int ch;


	StopWatch watch;

	do 
	{
		ch = _getch();
		ch = toupper(ch);

	} while (ch !='Q');

	double dTimeDuration = watch.GetElapsedTime(true);

	client.disconnect(false);


	//Show statistics :


	//Calculate total packets received : 
	double nTotal = 0;
	statsMapT::iterator it;
	statsMapT& statsMap = client.getStatsMap();
	for (it = statsMap.begin() ;it!=statsMap.end();it++)
	{
		nTotal += it->second->uPacketsCount;
	}
	//Deduce the download rate :
	double packetAvgSize = 8008;
	int nPacketsRate = (int) (((double) nTotal) / dTimeDuration) ;
	int nMBytesPerSeconds = (int) (packetAvgSize * (((double) nTotal) / dTimeDuration) /( 1024*1024));




	cout << "Total received : " << nTotal << "\tDownload rate :" << nMBytesPerSeconds << " MBps\tPackets rate :" << nPacketsRate << " packet per sec" << std::endl;





	for (it = statsMap.begin() ;it!=statsMap.end();it++)
	{
		ChannelPacketsInfo* pInfo = it->second;

		int nPercent = pInfo->uPacketsCount* 100 / nTotal;
		int nRejection = (int) ((double)(pInfo->uMissedCount)* 100 / (double)(pInfo->uMissedCount + pInfo->uPacketsCount));

		cout << "#" << it->first << " : " << pInfo->uPacketsCount << " packets received\t" << nPercent << " % of total\tRejection rate :" << nRejection << " %Duplicates :" << pInfo->nDuplicates << std::endl;
	}

	cout << std::endl;
	cout << "Press a key to quit" << std::endl;

	ch = _getch();

	return 0;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Apache License, Version 2.0


Written By
Technical Lead
Tunisia Tunisia
Services:
http://www.pushframework.com/?page_id=890

Comments and Discussions