Index: trunk/src/subprojects/network/Makefile.am
===================================================================
--- trunk/src/subprojects/network/Makefile.am	(revision 5827)
+++ trunk/src/subprojects/network/Makefile.am	(revision 5996)
@@ -15,4 +15,6 @@
 network_SOURCES=  network_unit_test.cc \
                   simple_sync.cc \
+		  read_sync.cc \
+		  write_sync.cc \
                   \
                   \
@@ -21,9 +23,14 @@
                   $(MAINSRCDIR)/util/loading/load_param.cc \
                   $(MAINSRCDIR)/lib/util/substring.cc \
-                  $(MAINSRCDIR)/lib/util/helper_functions.cc 
+                  $(MAINSRCDIR)/util/loading/load_param_description.cc \
+                  $(MAINSRCDIR)/lib/util/helper_functions.cc \
+                  $(MAINSRCDIR)/lib/util/executor/executor.cc \
+                  $(MAINSRCDIR)/lib/util/multi_type.cc 
 
 
 
 noinst_HEADERS  =  network_unit_test.h \
-                   simple_sync.h
+                   simple_sync.h \
+		   read_sync.h \
+		   write_sync.h
 
Index: trunk/src/subprojects/network/network_unit_test.cc
===================================================================
--- trunk/src/subprojects/network/network_unit_test.cc	(revision 5827)
+++ trunk/src/subprojects/network/network_unit_test.cc	(revision 5996)
@@ -8,8 +8,10 @@
 #include "network_manager.h"
 #include "network_socket.h"
+#include "server_socket.h"
 #include "network_stream.h"
 #include "synchronizeable.h"
 
 #include "simple_sync.h"
+#include "read_sync.h"
 
 int verbose = 4;
@@ -25,4 +27,5 @@
   printf(" --server [port number]     creates a test server\n");
   printf(" --client [address] [port]  connects to a server\n");
+  printf(" --listen [address] [port]  just listens to this connection");
   printf("\n");
 }
@@ -34,84 +37,79 @@
   IPaddress ip;
   SDLNet_ResolveHost(&ip, "127.0.0.1", 9999);
-  NetworkSocket server;
+  ServerSocket server;
   server.listen(9999);
-  SDL_Delay(20);
-
-  NetworkSocket client(ip);
+
+  NetworkSocket client1(ip);
+
+  NetworkSocket server1 = server.getNewSocket();
+
+  NetworkSocket client2(ip);
+
+  NetworkSocket server2 = server.getNewSocket();
 
   char buf[1024];
 
-  printf("read from client before sending data\n");
-  printf("result: %d bytes\n", client.readBytes((byte*)buf, 1024));
-
-  printf("read from server before sending data\n");
-  printf("result: %d bytes\n", server.readBytes((byte*)buf, 1024));
+  printf("read from client1 before sending data\n");
+  printf("result: %d bytes\n", client1.readPacket((byte*)buf, 1024));
+
+  printf("read from client2 before sending data\n");
+  printf("result: %d bytes\n", client2.readPacket((byte*)buf, 1024));
 
   int n;
-  char * str1 = "client to server";
-  char * str2 = "server to client";
-  n = client.writeBytes((byte*)str1, strlen(str1)+1);
-  printf("%d bytes send from client\n", n);
-  n = server.writeBytes((byte*)str2, strlen(str2)+1);
-  printf("%d bytes send from server\n", n);
+  char * str1 = "client1 to server";
+  char * str2 = "server1 to client";
+  char * str3 = "client2 to server";
+  char * str4 = "server2 to client";
+  n = client1.writePacket((byte*)str1, strlen(str1)+1);
+  printf("%d bytes send from client1\n", n);
+  n = server1.writePacket((byte*)str2, strlen(str2)+1);
+  printf("%d bytes send from server1\n", n);
+  n = client2.writePacket((byte*)str3, strlen(str3)+1);
+  printf("%d bytes send from client2\n", n);
+  n = server2.writePacket((byte*)str4, strlen(str4)+1);
+  printf("%d bytes send from server2\n", n);
   SDL_Delay(1000);
 
-  printf("read from server\n");
-  n = server.readBytes((byte*)buf, 1024);
+  printf("read from server1\n");
+  n = server1.readPacket((byte*)buf, 1024);
   printf("read %d bytes\n", n);
   if (n<0)
     return -1;
 
-  printf("data: %s\n", buf);
-  printf("read from client\n");
-  n = client.readBytes((byte*)buf, 1024);
-
+  printf("data: '%s'\n", buf);
+
+  printf("read from server2\n");
+  n = server2.readPacket((byte*)buf, 1024);
   printf("read %d bytes\n", n);
   if (n<0)
     return -1;
 
-  printf("data: %s\n", buf);
-
-  printf("testing a bigger amount of data\n");
-
-#define _N_ELEMENTS 212994
-  char sendbuf[_N_ELEMENTS+1];
-  char recvbuf[_N_ELEMENTS+1];
-  sendbuf[_N_ELEMENTS] = '\0';
-  recvbuf[_N_ELEMENTS] = '\0';
-
-  for (int i = 0; i<_N_ELEMENTS; i++)
-    sendbuf[i] = i%26 + 65;
-
-  printf("write\n");
-  printf("result = %d\n", client.writeBytes((byte*)sendbuf, _N_ELEMENTS));
-
-  SDL_Delay(50);
-
-  printf("read\n");
-  int nbytes = server.readBytes((byte*)recvbuf, _N_ELEMENTS);
-  int offset = nbytes;
-
-  while (nbytes>0)
-  {
-    SDL_Delay(10);
-    //printf("read\n");
-    nbytes = server.readBytes((byte*)recvbuf+offset, _N_ELEMENTS-offset);
-    offset += nbytes;
-    //printf("nbytes=%d, offset=%d\n", nbytes, offset);
-  }
-
-  printf("strcmp = %d (0 is good :D not 0 is evil)\noffset = %d\n", strncmp(sendbuf, recvbuf, _N_ELEMENTS), offset);
-
-  //printf("%s\n%s\n", sendbuf, recvbuf);
-
-  for (int i = 0; i<_N_ELEMENTS; i++)
-  {
-    if (sendbuf[i]!=recvbuf[i])
-    {
-      printf("byte %d is the first difference\n", i+1);
-      break;
-    }
-  }
+  printf("data: '%s'\n", buf);
+
+  printf("read from client1\n");
+  n = client1.readPacket((byte*)buf, 1024);
+  printf("read %d bytes\n", n);
+  if (n<0)
+    return -1;
+
+  printf("data: '%s'\n", buf);
+
+  printf("read from client2\n");
+  n = client2.readPacket((byte*)buf, 1024);
+  printf("read %d bytes\n", n);
+  if (n<0)
+    return -1;
+
+  printf("data: '%s'\n", buf);
+
+  //sending bigger packets than 255 is not supported
+
+  printf("try to send more than 255 bytes\n");
+  printf("result: %d\n", client1.writePacket((byte*)buf, 1000));
+
+  server1.writePacket((byte*)str1, strlen(str1)+1);
+  SDL_Delay(500);
+  printf("try to read with a too small buffer\n");
+  printf("result: %d\n", client1.readPacket((byte*)buf, strlen(str1)));
 
   return 0;
@@ -131,5 +129,5 @@
 
   /* create the network manager */
-  NetworkManager* nm = new NetworkManager();
+  NetworkManager* nm = NetworkManager::getInstance();
 
   /* initialize the network manager */
@@ -143,5 +141,6 @@
   int error = SDLNet_ResolveHost(&ip, "127.0.0.1", port);
   //SDLNet_ResolveHost(&ip, "localhost", port);
-  if(error == -1) printf("\n\nerror on address resolution, program inconsistancy\n\n");
+  if(error == -1)
+    printf("\n\nerror on address resolution, program inconsistancy\n\n");
   nm->establishConnection(ip, *clientSync);
   /* adding some break for connection setup */
@@ -149,5 +148,6 @@
 
   /* synchronize the data 1 time (increment for longer tests) */
-  for( int i = 0; i < 3; i++) {
+  for( int i = 0; i < 3; i++)
+  {
     nm->synchronize();
     /* simulate the network delay */
@@ -177,5 +177,6 @@
 int startServer(int argc, char** argv)
 {
-  if( argc <= 2) {
+  if( argc <= 2)
+  {
     printf(" Wrong arguments try following notations:\n");
     printf("   --server [port number]\n");
@@ -186,15 +187,20 @@
   printf("Starting Server on port %i\n", port);
 
-  NetworkManager* netMan = new NetworkManager();
+  NetworkManager* netMan = NetworkManager::getInstance();
   Synchronizeable* ss = new SimpleSync("Server\0");
 
-  //NetworkStream* server = new NetworkStream(port, ss, NET_SERVER);
   netMan->createServer(*ss, port);
   SDL_Delay(20);
 
-  for(;;) {
+  for(;;)
+  {
     netMan->synchronize();
     SDL_Delay(500);
   }
+
+  delete netMan;
+  delete ss;
+
+
   return 0;
 }
@@ -203,8 +209,9 @@
 int startClient(int argc, char** argv)
 {
-  if( argc < 3) {
+  if( argc < 3)
+  {
     printf(" Wrong arguments try following notations:\n");
     printf("   --client [server ip] [port number]\n");
-    printf("   --server [server name] [port number]\n");
+    printf("   --client [server name] [port number]\n");
     return 0;
   }
@@ -216,18 +223,56 @@
   IPaddress ip;
   int error = SDLNet_ResolveHost(&ip, name, port);
-  //SDLNet_ResolveHost(&ip, "localhost", port);
-  if(error == -1) printf("\n\nerror on address resolution, program inconsistancy\n\n");
-
-  NetworkManager* netMan = new NetworkManager();
+  if(error == -1)
+    printf("\n\nerror on address resolution, program inconsistancy\n\n");
+
+  NetworkManager* netMan = NetworkManager::getInstance();
   Synchronizeable* ss = new SimpleSync("Client\0");
 
   netMan->establishConnection(ip, *ss);
 
-  for(;;) {
+  for(;;)
+  {
     netMan->synchronize();
     SDL_Delay(500);
   }
 
-  //NetworkStream* client = new NetworkStream(ip, ss, NET_CLIENT);
+
+  delete netMan;
+  delete ss;
+
+  return 0;
+}
+
+
+
+int startListen(int argc, char** argv)
+{
+  if( argc < 3)
+  {
+    printf(" Wrong arguments try following notations:\n");
+    printf("   --listen [server ip] [port number]\n");
+    printf("   --listen [server name] [port number]\n");
+    return 0;
+  }
+
+  char* name = argv[2];
+  int port = atoi(argv[3]);
+  printf("Connecting to %s, on port %i\n", name, port);
+
+  IPaddress ip;
+  int error = SDLNet_ResolveHost(&ip, name, port);
+  if(error == -1)
+    printf("\n\nerror on address resolution, program inconsistancy\n\n");
+
+  NetworkManager* netMan = NetworkManager::getInstance();
+  Synchronizeable* ss = new ReadSync("WriteSync\0");
+
+  netMan->establishConnection(ip, *ss);
+
+  for(;;)
+  {
+    netMan->synchronize();
+    SDL_Delay(10);
+  }
 
 
@@ -253,8 +298,14 @@
   {
     //else if(!strcmp( "--gui", argv[i]) || !strcmp("-g", argv[i])) showGui = true;
-    if (! strcmp( "--sockettest", argv[i]) || !strcmp("-st", argv[i])) return testSocket(argc, argv);
-    else if (! strcmp( "--frameworktest", argv[i]) || !strcmp("-ft", argv[i])) return testFramework(argc, argv);
-    else if (! strcmp( "--server", argv[i]) || !strcmp("-s", argv[i])) return startServer(argc, argv);
-    else if (! strcmp( "--client", argv[i]) || !strcmp("-c", argv[i])) return startClient(argc, argv);
+    if (! strcmp( "--sockettest", argv[i]) || !strcmp("-st", argv[i]))
+      return testSocket(argc, argv);
+    else if (! strcmp( "--frameworktest", argv[i]) || !strcmp("-ft", argv[i]))
+      return testFramework(argc, argv);
+    else if (! strcmp( "--server", argv[i]) || !strcmp("-s", argv[i]))
+      return startServer(argc, argv);
+    else if (! strcmp( "--client", argv[i]) || !strcmp("-c", argv[i]))
+      return startClient(argc, argv);
+    else if (! strcmp( "--listen", argv[i]) || !strcmp("-l", argv[i]))
+      return startListen(argc, argv);
   }
 
@@ -270,4 +321,3 @@
   //vprintf(line, arguments);
   printf("%s", line);
-
-}
+}
Index: trunk/src/subprojects/network/read_sync.cc
===================================================================
--- trunk/src/subprojects/network/read_sync.cc	(revision 5996)
+++ trunk/src/subprojects/network/read_sync.cc	(revision 5996)
@@ -0,0 +1,100 @@
+/*
+  orxonox - the future of 3D-vertical-scrollers
+
+  Copyright (C) 2004 orx
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+      the Free Software Foundation; either version 2, or (at your option)
+      any later version.
+
+### File Specific:
+    main-programmer: Patrick Boenzli
+    co-programmer:
+*/
+
+
+/* this is for debug output. It just says, that all calls to PRINT() belong to the DEBUG_MODULE_NETWORK module
+          For more information refere to https://www.orxonox.net/cgi-bin/trac.cgi/wiki/DebugOutput
+*/
+#define DEBUG_MODULE_NETWORK
+
+#include "read_sync.h"
+
+#include "debug.h"
+
+
+/**
+ *  default constructor
+ */
+ReadSync::ReadSync(const char* name)
+  : Synchronizeable(name)
+{
+  /* define the local buffer size */
+
+  this->inLength = 100;
+  this->recLength = 0;
+  this->inData = new byte[this->inLength];
+
+  /* init the buffer data */
+  for( int i = 0; i < this->inLength; i++)
+  {
+    this->inData[i] = 0;
+  }
+
+}
+
+
+/**
+ *  default destructor deletes all unneded stuff
+ */
+ReadSync::~ReadSync()
+{
+
+  if( this->inData)
+    delete[] this->inData;
+}
+
+
+/**
+ *  write data to Synchronizeable
+ */
+void ReadSync::writeBytes(const byte* data, int length)
+{
+  PRINTF(0)("ReadSync: got %i bytes of data\n", length);
+  this->recLength = length;
+  if(this->inLength < length)
+    PRINTF(0)("ERROR: local buffer is smaller than the data to receive.\n");
+
+  /* copy the data localy */
+  for( int i = 0; i < length; i++)
+  {
+    this->inData[i] = data[i];
+  }
+  /* and debug output */
+  this->writeDebug();
+}
+
+
+/**
+ *  read data from Synchronizeable
+ */
+int ReadSync::readBytes(byte* data)
+{
+  return 0;
+}
+
+
+void ReadSync::writeDebug() const
+{
+  PRINTF(0)("Write in bytes: \t(0 <-) |");
+  for(int i = 0; i < this->recLength; i++)
+  {
+    PRINT(0)(" [%u] ",this->inData[i]);
+  }
+  PRINT(0)("|\n");
+}
+
+
+void ReadSync::readDebug() const
+{}
Index: trunk/src/subprojects/network/read_sync.h
===================================================================
--- trunk/src/subprojects/network/read_sync.h	(revision 5996)
+++ trunk/src/subprojects/network/read_sync.h	(revision 5996)
@@ -0,0 +1,33 @@
+/*!
+ * @file simple_sync.h
+ *  implementation of a network sync test
+ */
+
+#ifndef _READ_SYNC
+#define _READ_SYNC
+
+#include "synchronizeable.h"
+
+
+class ReadSync : public Synchronizeable
+  {
+  public:
+    ReadSync(const char* name);
+    ~ReadSync();
+
+    virtual void writeBytes(const byte* data, int length);
+    virtual int readBytes(byte* data);
+
+
+  private:
+    virtual void writeDebug() const;
+    virtual void readDebug() const;
+
+
+  private:
+    byte* inData;
+    int   inLength;
+    int   recLength;
+  };
+
+#endif /* _READ_SYNC */
Index: trunk/src/subprojects/network/simple_sync.cc
===================================================================
--- trunk/src/subprojects/network/simple_sync.cc	(revision 5827)
+++ trunk/src/subprojects/network/simple_sync.cc	(revision 5996)
@@ -86,5 +86,5 @@
  *  read data from Synchronizeable
  */
-int SimpleSync::readBytes(byte* data) const
+int SimpleSync::readBytes(byte* data)
 {
   PRINTF(0)("SimpleSync: sent %i bytes of data\n", this->outLength);
Index: trunk/src/subprojects/network/simple_sync.h
===================================================================
--- trunk/src/subprojects/network/simple_sync.h	(revision 5827)
+++ trunk/src/subprojects/network/simple_sync.h	(revision 5996)
@@ -17,5 +17,5 @@
 
     virtual void writeBytes(const byte* data, int length);
-    virtual int readBytes(byte* data) const;
+    virtual int readBytes(byte* data);
 
 
Index: trunk/src/subprojects/network/write_sync.cc
===================================================================
--- trunk/src/subprojects/network/write_sync.cc	(revision 5996)
+++ trunk/src/subprojects/network/write_sync.cc	(revision 5996)
@@ -0,0 +1,123 @@
+/*
+  orxonox - the future of 3D-vertical-scrollers
+
+  Copyright (C) 2004 orx
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+      the Free Software Foundation; either version 2, or (at your option)
+      any later version.
+
+### File Specific:
+    main-programmer: Patrick Boenzli
+    co-programmer:
+*/
+
+
+/* this is for debug output. It just says, that all calls to PRINT() belong to the DEBUG_MODULE_NETWORK module
+          For more information refere to https://www.orxonox.net/cgi-bin/trac.cgi/wiki/DebugOutput
+*/
+#define DEBUG_MODULE_NETWORK
+
+#include "write_sync.h"
+
+#include "debug.h"
+
+
+/**
+ *  default constructor
+ */
+WriteSync::WriteSync(const char* name)
+  : Synchronizeable(name)
+{
+  /* define the local buffer size */
+  this->outLength = 10;
+  this->recLength = 0;
+  this->inLength = 40;
+  this->outData = new byte[this->outLength];
+  this->inData = new byte[this->inLength];
+
+  /* init the buffer data */
+  for( int i = 0; i < this->outLength; i++)
+  {
+    this->outData[i] = i;
+  }
+  for( int i = 0; i < this->inLength; i++)
+  {
+    this->inData[i] = 0;
+  }
+
+}
+
+
+/**
+ *  default destructor deletes all unneded stuff
+ */
+WriteSync::~WriteSync()
+{
+  if( this->outData)
+    delete[] this->outData;
+  if( this->inData)
+    delete[] this->inData;
+}
+
+
+/**
+ *  write data to Synchronizeable
+ */
+void WriteSync::writeBytes(const byte* data, int length)
+{
+  PRINTF(0)("WriteSync: got %i bytes of data\n", length);
+  this->recLength = length;
+  if(this->inLength < length)
+    PRINTF(0)("ERROR: local buffer is smaller than the data to receive.\n");
+
+  /* copy the data localy */
+  for( int i = 0; i < length; i++)
+  {
+    this->inData[i] = data[i];
+  }
+  /* and debug output */
+  this->writeDebug();
+}
+
+
+/**
+ *  read data from Synchronizeable
+ */
+int WriteSync::readBytes(byte* data)
+{
+  PRINTF(0)("WriteSync: sent %i bytes of data\n", this->outLength);
+
+  /* debug msg */
+  this->readDebug();
+
+  /* write the test message */
+  for( int i = 0; i < this->outLength; i++)
+    data[i] = this->outData[i];
+
+  /* return the length of the test */
+  return this->outLength;
+}
+
+
+void WriteSync::writeDebug() const
+{
+  PRINTF(0)("Write in bytes: \t(0 <-) |");
+  for(int i = 0; i < this->recLength; i++)
+  {
+    PRINT(0)(" [%u] ",this->inData[i]);
+  }
+  PRINT(0)("|\n");
+}
+
+
+void WriteSync::readDebug() const
+{
+  PRINTF(0)("Read out bytes: \t(0 ->) |");
+  for(int i = 0; i < this->outLength; i++)
+  {
+    PRINT(0)(" [%u] ",this->outData[i]);
+  }
+  PRINT(0)("|\n");
+}
Index: trunk/src/subprojects/network/write_sync.h
===================================================================
--- trunk/src/subprojects/network/write_sync.h	(revision 5996)
+++ trunk/src/subprojects/network/write_sync.h	(revision 5996)
@@ -0,0 +1,35 @@
+/*!
+ * @file simple_sync.h
+ *  implementation of a network sync test
+ */
+
+#ifndef _WRITE_SYNC
+#define _WRITE_SYNC
+
+#include "synchronizeable.h"
+
+
+class WriteSync : public Synchronizeable
+  {
+  public:
+    WriteSync(const char* name);
+    ~WriteSync();
+
+    virtual void writeBytes(const byte* data, int length);
+    virtual int readBytes(byte* data);
+
+
+  private:
+    virtual void writeDebug() const;
+    virtual void readDebug() const;
+
+
+  private:
+    byte* inData;
+    int   inLength;
+    int   recLength;
+    byte* outData;
+    int   outLength;
+  };
+
+#endif /* _WRITE_SYNC */
