Index: branches/network/src/lib/network/connection_monitor.cc
===================================================================
--- branches/network/src/lib/network/connection_monitor.cc	(revision 5617)
+++ branches/network/src/lib/network/connection_monitor.cc	(revision 5618)
@@ -15,4 +15,7 @@
 
 #include "connection_monitor.h"
+#include <debug.h>
+#include <SDL/SDL.h>
+#include <string.h>
 
 /* using namespace std is default, this needs to be here */
@@ -20,42 +23,112 @@
 
 ConnectionMonitor::ConnectionMonitor()
- {
+{
 
-         totalReceivedPackets=0;
-         totalLostPackets=0;
-         //packetSize=?;
+  /* set the class id for the base object and add ist to class list*/
+  this->setClassID(CL_CONNECTION_MONITOR, "ConnectionMonitor");
 
-         currentPacketID=0;
-         currentDatarate=0;
-         timeForLastFewPackets=0;
+  /*initialize variables*/
 
- }
+  /*Data of the lifetime of the ConnectionMonitor Object*/
+  packetToAverage = 5;
+
+  startTime= SDL_GetTicks();
+  totalReceivedPackets=0;
+  averageDatarate=0;
+  totalLostPackets=0;
+  totalPacketloss=0;
+
+  /*Data of the current packet*/
+  currentPacketID=0;
+  currentPacketTick=0;
+  lastPacketID=0;
+  lastPacketTick=0;
+  currentDelay=0;
+
+  /*Data of the last n packets (n is specified by paxketsToAverage)*/
+  sizeOfLastFewPackets=0;
+  currentDatarate=0;
+  lastFewDelays = new unsigned int [packetToAverage];
+  lastFewPackets = new byte* [packetToAverage];
+  packetCounter=0;
+
+
+}
 
 
 ConnectionMonitor::~ConnectionMonitor()
- {
+{
+
+
+}
 
 
 
+void ConnectionMonitor::processPacket(byte* currentPacket, unsigned int packetLength)
+{
+  /*Process the current Package*/
+  currentPacketTick = SDL_GetTicks();
+  currentDelay = currentPacketTick - lastPacketTick;
 
- }
+  /*  Only for Udp
+      if(currentPacketID - lastPacketID > 1)
+      {
+              totalLostPackets += currentPacketID - lastPacketID;
+      }
+
+     totalPacketloss = (totalLostPackets/totalReceivedPackets)*100 ;
+  */
+
+  /*Do whats needed for Averaging*/
+
+  if(packetCounter = packetToAverage)
+    {
+      computeAverageStatistic();
+      displayStatistic();
+      packetCounter = 0;
+    }
+
+  lastFewDelays[packetCounter] = currentDelay;
+  lastFewPackets[packetCounter] = currentPacket;
+  sizeOfLastFewPackets += packetLength;
 
 
+  /*Update the lifetime Variables*/
+  totalReceivedPackets ++;
+  averageDatarate = totalReceivedPackets/(currentPacketTick - startTime);
 
- void ConnectionMonitor::processPacket(byte* packet)
- {
+  /*Preparefor the next Packet*/
+  lastPacketTick = currentPacketTick;
+  packetCounter++;
+}
 
 
+/* Compute the value of current Datarate*/
+void ConnectionMonitor::computeAverageStatistic()
+{
+  int timeForLastFewPackets;
+  for(int i=0;i <= packetToAverage-1;i++)
+    timeForLastFewPackets += lastFewDelays[i];
 
- }
+  currentDatarate = packetToAverage/timeForLastFewPackets;
+}
 
 
- void ConnectionMonitor::displayStatistic()
- {
+void ConnectionMonitor::displayStatistic()
+{
+  PRINT(0)("============================================\n");
+  PRINT(0)("Connection Monitor Network Statistics:\n");
+  PRINT(0)("Total received packets:",totalReceivedPackets);
+  PRINT(0)("Average datarate :\n",averageDatarate);
+  PRINT(0)("Total lost packets:",totalLostPackets);
+  PRINT(0)("Packetloss [%] :\n",totalPacketloss);
 
+  PRINT(0)("Current datarate :\n",currentDatarate);
+  PRINT(0)("Delays of the last few packets :\n",currentDelay);
+  for(int i=1 ;i <= packetToAverage-1;i++)
+    PRINT(0)("%i ",lastFewDelays[i]);
 
+  PRINT(0)("============================================\n");
 
+}
 
-
- }
-
Index: branches/network/src/lib/network/connection_monitor.h
===================================================================
--- branches/network/src/lib/network/connection_monitor.h	(revision 5617)
+++ branches/network/src/lib/network/connection_monitor.h	(revision 5618)
@@ -11,27 +11,42 @@
 
 class ConnectionMonitor : virtual public BaseObject
-{
-        public:
-                        ConnectionMonitor();
-                        ~ConnectionMonitor();
+  {
+  public:
+    ConnectionMonitor();
+    ~ConnectionMonitor();
 
-    void                processPacket(byte* packet);
+    void                processPacket(byte* packet, unsigned int packetLength);
 
 
-        private:
+  private:
 
 
     void                displayStatistic();
+    void                computeAverageStatistic();
+
+    /*Data of the lifetime of the ConnectionMonitor Object*/
+    unsigned int        packetToAverage;
 
     unsigned int        totalReceivedPackets;
+    float               averageDatarate;
     unsigned int        totalLostPackets;
-    unsigned int        packetSize;
+    float               totalPacketloss;
+    unsigned int        startTime;
 
+    /*Data of the current packet*/
     unsigned int        currentPacketID;
+    unsigned int        currentPacketTick;
+    unsigned int        lastPacketID;
+    unsigned int        lastPacketTick;
+    unsigned int        currentDelay;
+
+    /*Data of the last n packets (n is specified by paxketsToAverage)*/
+    unsigned int        sizeOfLastFewPackets;
     unsigned int        currentDatarate;
-    unsigned int        timeForLastFewPackets;
+    byte**              lastFewPackets;
+    unsigned int*       lastFewDelays;
+    unsigned int        packetCounter;
 
-};
+  };
 
 #endif
-
