Index: branches/network/src/Makefile.am
===================================================================
--- trunk/src/Makefile.am	(revision 5995)
+++ branches/network/src/Makefile.am	(revision 5999)
@@ -24,5 +24,6 @@
                        lib/parser/ini_parser/libIniParser.a \
                        lib/gui/gl_gui/libORXglgui.a \
-                       lib/shell/libORXshell.a
+                       lib/shell/libORXshell.a \
+                       lib/network/libORXnet.a 
 
 orxonox_LDADD = util/libORXutils.a \
@@ -41,4 +42,5 @@
                 lib/gui/gl_gui/libORXglgui.a \
                 lib/shell/libORXshell.a \
+                lib/network/libORXnet.a \
                 $(GTK2_LIBS) $(GTHREAD_LIBS) $(CURL_LIBS)
 
Index: branches/network/src/defs/class_id.h
===================================================================
--- trunk/src/defs/class_id.h	(revision 5995)
+++ branches/network/src/defs/class_id.h	(revision 5999)
@@ -224,5 +224,6 @@
   CL_NETWORK_PROTOCOL           =    0x00000b02,
   CL_NETWORK_SOCKET             =    0x00000b03,
-  CL_CONNECTION_MONITOR         =    0x00000b04,
+  CL_SERVER_SOCKET              =    0X00000b04,
+  CL_CONNECTION_MONITOR         =    0x00000b05,
 
 
Index: branches/network/src/defs/debug.h
===================================================================
--- trunk/src/defs/debug.h	(revision 5995)
+++ branches/network/src/defs/debug.h	(revision 5999)
@@ -110,5 +110,5 @@
 #endif
 #ifndef NO_SHELL
-#define PRINT_EXEC       ShellBuffer::addBufferLineStatic
+#define PRINT_EXEC       printf //ShellBuffer::addBufferLineStatic
 #else /* NO_SHELL */
 #define PRINT_EXEC       printf
Index: branches/network/src/defs/globals.h
===================================================================
--- trunk/src/defs/globals.h	(revision 5995)
+++ branches/network/src/defs/globals.h	(revision 5999)
@@ -91,12 +91,21 @@
 
 #define  ORXONOX_LICENSE_SHORT \
-"orxonox - the future of 3D-vertical-scrollers\n" \
-"\n" \
-"Copyright (C) 2004 orx\n" \
-"\n" \
-"This program is free software; you can redistribute it and/or modify\n" \
-"it under the terms of the GNU General Public License as published by\n" \
-"the Free Software Foundation; either version 2, or (at your option)\n" \
-"any later version.\n"
+    "Orxonox - The Future of 3D-Action-Game\n" \
+    "\n" \
+    "Copyright (C) 2004 orx\n" \
+    "\n" \
+    "This program is free software; you can redistribute it and/or modify\n" \
+    "it under the terms of the GNU General Public License as published by\n" \
+    "the Free Software Foundation; either version 2, or (at your option)\n" \
+    "any later version.\n" \
+    "\n" \
+    "This program is distributed in the hope that it will be useful,\n" \
+    "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"  \
+    "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"   \
+    "GNU General Public License for more details.\n" \
+    "\n" \
+    "You should have received a copy of the GNU General Public License\n" \
+    "along with this program; if not, write to the Free Software Foundation,\n" \
+    "Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n"
 
 
Index: branches/network/src/lib/network/Makefile.am
===================================================================
--- trunk/src/lib/network/Makefile.am	(revision 5995)
+++ branches/network/src/lib/network/Makefile.am	(revision 5999)
@@ -10,5 +10,6 @@
 		      network_stream.cc \
                       data_stream.cc \
-                      network_protocol.cc
+                      network_protocol.cc \
+		      server_socket.cc
 
 
@@ -20,4 +21,5 @@
 		 network_stream.h \
                  data_stream.h \
-                 network_protocol.h
+                 network_protocol.h \
+		 server_socket.h
 
Index: branches/network/src/lib/network/network_manager.cc
===================================================================
--- trunk/src/lib/network/network_manager.cc	(revision 5995)
+++ branches/network/src/lib/network/network_manager.cc	(revision 5999)
@@ -35,36 +35,5 @@
 
 
-/************************************
-  What you will see here are the function definitions from the header file (network_manager.h) with doxygen documentation. Here is an example:
-
-
- In file network_manager.h
-
- class NetworkManager
- {
-   int doSomeStuff(float argument, float* pointer);
- }
-
- will be implemented in the source file as follows:
-
- In file network_manager.cc
-
- / **
-  *  this is the short description for this function: it just does some stuff
-  * @param argument: this is the first argument, stuff...
-  * @param pointer:  this is the pointer to nowhereland
-  * return: whatever the function returns: for example an index, number, etc.
-  * /
- int NetworkManager::doSomeStuff(float argument, float* pointer)
- {
-   // whaterver you want to do
- }
-
-
- if you want to make automake compile your files: you will want to add the file names to the local Makefile.am
-
- ************************************/
-
-
+NetworkManager* NetworkManager::singletonRef = NULL;
 
 /**
@@ -79,4 +48,6 @@
   this->netStreamList = NULL;
   this->syncList = NULL;
+  this->tmpStream = NULL;
+  this->hostID = -1;
 
   PRINTF(0)("NetworkManager created\n");
@@ -114,8 +85,29 @@
  *  creates a connection from one object to a host
  * @param hostName: the name of the destination host
- * @param synchronizeable: reference to the sync object
  */
-NetworkStream& establishConnection(const char& hostName, const Synchronizeable& sync)
-{}
+int NetworkManager::establishConnection(const char* name, unsigned int port)
+{
+  IPaddress ipAddress;
+  int error = SDLNet_ResolveHost(&ipAddress, name, port);
+  if( error == -1) {
+    printf("\n\nerror on address resolution, program inconsistency\n\n");
+    return -1;
+  }
+
+  this->tmpStream = new NetworkStream(ipAddress, NET_CLIENT);
+  return 1;
+}
+
+
+/**
+ *  creates a new NetworkStream of server type
+ * @param port: number of the TCP port
+ */
+int NetworkManager::createServer(unsigned int port)
+{
+  this->tmpStream = new NetworkStream(port, NET_SERVER);
+  SDL_Delay(20);
+  return 1;
+}
 
 
@@ -127,8 +119,8 @@
 NetworkStream& NetworkManager::establishConnection(IPaddress& address, Synchronizeable& sync)
 {
-  printf("Establish connection to server %s, on port %u\n", SDLNet_ResolveIP(&address), address.port);
   /* creating a new network stream, it will register itself automaticaly to the class list */
-  NetworkStream* netStream = new NetworkStream(address, sync, NET_CLIENT);
+  this->tmpStream = new NetworkStream(address, sync, NET_CLIENT);
 }
+
 
 /**
@@ -140,5 +132,5 @@
   PRINTF(0)("Create a new server socket\n");
   /* creating a new network stream, it will register itself automaticaly to the class list */
-  NetworkStream* netStream = new NetworkStream(port, sync, NET_SERVER);
+  this->tmpStream = new NetworkStream(port, sync, NET_SERVER);
 }
 
@@ -153,4 +145,9 @@
 
 
+void NetworkManager::connectSynchronizeable(Synchronizeable& sync)
+{
+  this->tmpStream->connectSynchronizeable(sync);
+}
+
 
 /**
@@ -163,6 +160,17 @@
     std::list<BaseObject*>::const_iterator stream;
     for (stream = this->netStreamList->begin(); stream != this->netStreamList->end(); ++stream)
-      static_cast<NetworkStream*>(*stream)->processData();
+      if( static_cast<NetworkStream*>(*stream)->isActive())
+        static_cast<NetworkStream*>(*stream)->processData();
+
   }
 
 }
+
+/**
+ * Sets the hostID to a specific number
+ * @param id: The new ID
+ */
+void NetworkManager::setHostID(int id)
+{
+  this->hostID = id;
+}
Index: branches/network/src/lib/network/network_manager.h
===================================================================
--- trunk/src/lib/network/network_manager.h	(revision 5995)
+++ branches/network/src/lib/network/network_manager.h	(revision 5999)
@@ -19,5 +19,6 @@
 class NetworkStream;
 class Synchronizeable;
-template<typename> class tList;
+template<typename>
+class tList;
 
 /* and here is the class itsself*/
@@ -25,22 +26,38 @@
 {
 
-public:
+  public:
 
-  NetworkManager();
-  ~NetworkManager();
+    inline static NetworkManager* getInstance() { if (!NetworkManager::singletonRef) NetworkManager::singletonRef = new NetworkManager();
+      return NetworkManager::singletonRef; }
+    ~NetworkManager();
 
-  void initialize();
-  void shutdown();
+    void initialize();
+    void shutdown();
 
-  NetworkStream& establishConnection(IPaddress& address, Synchronizeable& sync);
-  NetworkStream& establishConnection(const char& hostName, const Synchronizeable& sync);
-  NetworkStream& createServer(Synchronizeable& sync, unsigned int port);
-  void shutdownConnection();
+    int establishConnection(const char* name, unsigned int port);
+    int createServer(unsigned int port);
 
-  void synchronize();
+    NetworkStream& establishConnection(IPaddress& address, Synchronizeable& sync);
+    NetworkStream& createServer(Synchronizeable& sync, unsigned int port);
+    void shutdownConnection();
 
-private:
-  const std::list<BaseObject*>*    netStreamList;            // list with refs to all network streams
-  const std::list<BaseObject*>*    syncList;                 // list of synchronizeables
+
+    void setHostID(int id);
+    /** Returns the hostID @return The hostID of the object */
+    inline int getHostID() { return this->hostID; };
+
+  private:
+    void connectSynchronizeable(Synchronizeable& sync);
+    void synchronize();
+
+    NetworkManager();
+
+
+  private:
+    const std::list<BaseObject*>*    netStreamList;            // list with refs to all network streams
+    const std::list<BaseObject*>*    syncList;                 // list of synchronizeables
+    static NetworkManager* singletonRef;           //!< Pointer to the only instance of this Class
+    NetworkStream*         tmpStream;              //!< FIXME: this is only for testing purposes
+    int hostID;                                    //!< The Host-ID of the Manager
 
 };
Index: branches/network/src/lib/network/network_socket.cc
===================================================================
--- trunk/src/lib/network/network_socket.cc	(revision 5995)
+++ branches/network/src/lib/network/network_socket.cc	(revision 5999)
@@ -47,4 +47,13 @@
 
 
+NetworkSocket::NetworkSocket( TCPsocket sock )
+{
+  this->init();
+  this->tcpSocket = sock;
+
+  SDL_CreateThread(thread_read, (void*)this);
+  SDL_CreateThread(thread_write, (void*)this);
+}
+
 void NetworkSocket::init()
 {
@@ -75,4 +84,6 @@
 }
 
+
+
 /**
  * Default destructor
@@ -85,6 +96,4 @@
   PRINTF(5)("SDL_net shutdown\n");
 
-  _isListening = false;
-
   SDL_DestroyMutex(incomingBufferMutex);
   SDL_DestroyMutex(outgoingBufferMutex);
@@ -113,47 +122,8 @@
   }
 
-  _isListening = false;
-
   SDL_CreateThread(thread_read, (void*)this);
   SDL_CreateThread(thread_write, (void*)this);
 }
 
-/**
- * Tells the NetworkSocket to listen on a specific port for incoming connections.
- * NetworkSocket::writeBytes(...) will have no effect until there is a valuable connection.
- * @param port
- */
-void NetworkSocket::listen(unsigned int port)
-{
-  _isListening = true;
-  //check if not already connected or listening
-  if (tcpSocket)
-  {
-    PRINTF(1)("NetworkSocket::listen: tcpSocket!=NULL! maybe you already called listen or connectToServer or did not call disconnectServer()!\n");
-    _isListening = false;
-    return;
-  }
-
-  IPaddress ip;
-
-  if (SDLNet_ResolveHost(&ip, NULL, port)==-1)
-  {
-    PRINTF(1)("SDLNet_ResolveHost: %s\n", SDLNet_GetError());
-    _isListening = false;
-    return;
-  }
-
-  tcpSocket = SDLNet_TCP_Open(&ip);
-
-  if (!tcpSocket)
-  {
-    PRINTF(1)("SDLNet_TCP_Open: %s\n", SDLNet_GetError());
-    _isListening = false;
-    return;
-  }
-
-  SDL_CreateThread(thread_listen, (void*)this);
-  SDL_CreateThread(thread_write, (void*)this);
-}
 
 /**
@@ -184,30 +154,4 @@
   PRINTF(0)("NetworkSocket::writeBytes()\n");
 #ifdef _USE_OUTGOING_BUFFER
-
-  //printf("length=%d, bufsize=%d\n", length, _OUTGOING_BUFFER_SIZE);
-//   if (length>_OUTGOING_BUFFER_SIZE)
-//   {
-//     int res = 0;
-//     int n = length / _OUTGOING_BUFFER_SIZE;
-//     if (length % _OUTGOING_BUFFER_SIZE != 0)
-//       n++;
-// //     printf("n=%d\n", n);
-//     SDL_Delay(500);
-//     for (int i = 0; i<n; i++)
-//     {
-// //       printf("i=%d\n", i);
-//       if (i==n-1)
-//       {
-//         res += writeBytes(data + i*_OUTGOING_BUFFER_SIZE, length-i*_OUTGOING_BUFFER_SIZE);
-// //         printf("res = %d\n", res);
-//       }
-//       else
-//       {
-//         res += writeBytes(data + i*_OUTGOING_BUFFER_SIZE, _OUTGOING_BUFFER_SIZE);
-// //         printf("res = %d\n", res);
-//       }
-//     }
-//     return res;
-//   }
 
 #define min(a,b) (a<b)?a:b
@@ -256,4 +200,5 @@
 int NetworkSocket::readBytes(byte * data, int length)
 {
+  PRINTF(0)("NetworkSocket::readBytes()\n");
   if (data==NULL)
     return 0;
@@ -299,40 +244,4 @@
 }
 
-/**
- * used to create a thread to listen
- * will call thrad_read when established connection
- * @param data: pointer to NetwortSocket
- */
-int NetworkSocket::thread_listen( void * data )
-{
-  NetworkSocket * self = (NetworkSocket*)data;
-  self->_isListening = true;
-  TCPsocket tempsocket;
-
-  tempsocket = SDLNet_TCP_Accept(self->tcpSocket);
-
-  while (!tempsocket && !self->terminateThread)
-    tempsocket = SDLNet_TCP_Accept(self->tcpSocket);
-
-  SDL_mutexP(self->socketMutex);
-  SDLNet_TCP_Close(self->tcpSocket);
-  self->tcpSocket = NULL;
-
-  if (!tempsocket)
-  {
-    printf("SDLNet_TCP_Accept: %s\n", SDLNet_GetError());
-    //printf("SDLNet_TCP_Accept: %s\n", SDLNet_GetError());
-    SDL_mutexV(self->socketMutex);
-    self->_isListening = false;
-    return -1;
-  }
-
-  self->tcpSocket = tempsocket;
-
-  SDL_mutexV(self->socketMutex);
-
-  self->_isListening = false;
-  return thread_read(data);
-}
 
 /**
@@ -354,5 +263,5 @@
 
     //if buffer is full
-    if (nbytestoread<=0 || self->_isListening)
+    if (nbytestoread<=0)
     {
       SDL_Delay(_MSECONDS_SLEEP_FULL_BUFFER);
@@ -405,5 +314,5 @@
 
     //if buffer is full
-    if (nbytestowrite<=0 || self->_isListening)
+    if (nbytestowrite<=0)
     {
       SDL_Delay(_MSECONDS_SLEEP_EMPTY_BUFFER);
@@ -442,2 +351,49 @@
 }
 
+bool NetworkSocket::writePacket( byte * data, int length )
+{
+  PRINTF(0)("NetworkSocket::writePacket()\n");
+  if (length>255)
+  {
+    PRINTF(1)("Packet length > 255!\n");
+    return false;
+  }
+
+  byte blen = length;
+
+  writeBytes(&blen, 1);
+  writeBytes(data, length);
+}
+
+int NetworkSocket::readPacket( byte * data, int maxLength )
+{
+  PRINTF(0)("NetworkSocket::readPacket()\n");
+  if (incomingBufferLength<1)
+  {
+    return 0;
+  }
+
+  byte blen = incomingBuffer[0];
+
+  if (blen>maxLength)
+  {
+    PRINTF(1)("Buffersize is too small (%d) for packet (%d)\n", maxLength, blen);
+    return 0;
+  }
+
+  if (blen>incomingBufferLength)
+  {
+    return 0;
+  }
+
+  readBytes(&blen, 1);
+  int res = readBytes(data, blen);
+
+  if (res!=blen)
+    return -1;
+  else
+    return blen;
+
+}
+
+
Index: branches/network/src/lib/network/network_socket.h
===================================================================
--- trunk/src/lib/network/network_socket.h	(revision 5995)
+++ branches/network/src/lib/network/network_socket.h	(revision 5999)
@@ -18,4 +18,5 @@
 //sleep if outgoing buffer is empty
 #define _MSECONDS_SLEEP_EMPTY_BUFFER 10
+
 
 /* contains memmove and memcpy */
@@ -62,5 +63,4 @@
   bool terminateThread;
 
-  static int thread_listen(void * data);
   static int thread_read(void * data);
 #ifdef _USE_OUTGOING_BUFFER
@@ -68,5 +68,9 @@
 #endif
 
-  bool _isListening;
+  int writeBytes(byte * data, int length);
+  int readBytes(byte * data, int length);
+  int readBlock(byte * data, int length);
+
+  void init();
 
 public:
@@ -74,15 +78,12 @@
   NetworkSocket();
   NetworkSocket(IPaddress ip);
+  NetworkSocket(TCPsocket sock);
   ~NetworkSocket();
 
   void connectToServer(IPaddress ip);
-  void listen(unsigned int port);
   void disconnectServer();
-  int writeBytes(byte * data, int length);
-  int readBytes(byte * data, int length);
-  int readBlock(byte * data, int length);
 
-private:
-  void init();
+  bool writePacket(byte * data, int length);
+  int readPacket(byte * data, int maxLength);
 
 };
Index: branches/network/src/lib/network/network_stream.cc
===================================================================
--- trunk/src/lib/network/network_stream.cc	(revision 5995)
+++ branches/network/src/lib/network/network_stream.cc	(revision 5999)
@@ -40,8 +40,9 @@
 
 NetworkStream::NetworkStream()
-  : DataStream()
+    : DataStream()
 {
   this->init();
   /* initialize the references */
+  this->type = NET_CLIENT;
   this->networkSocket = new NetworkSocket();
   this->networkProtocol = new NetworkProtocol();
@@ -50,8 +51,31 @@
 }
 
+NetworkStream::NetworkStream(IPaddress& address, NodeType type)
+{
+  this->type = type;
+  this->init();
+  this->networkSocket = new NetworkSocket(address);
+  this->networkProtocol = new NetworkProtocol();
+  this->synchronizeables = NULL;
+  this->connectionMonitor = new ConnectionMonitor();
+}
+
+
+NetworkStream::NetworkStream(unsigned int port, NodeType type)
+{
+  this->type = type;
+  this->init();
+  this->networkSocket = new NetworkSocket();
+//  this->networkSocket->listen(port);
+  this->networkProtocol = new NetworkProtocol();
+  this->synchronizeables = NULL;
+  this->connectionMonitor = new ConnectionMonitor();
+}
+
 
 NetworkStream::NetworkStream(IPaddress& address, Synchronizeable& sync, NodeType type)
-  : DataStream()
-{
+    : DataStream()
+{
+  this->type = type;
   this->init();
   this->networkSocket = new NetworkSocket(address);
@@ -59,16 +83,19 @@
   this->synchronizeables = &sync;
   this->connectionMonitor = new ConnectionMonitor();
+  this->bActive = true;
 }
 
 
 NetworkStream::NetworkStream(unsigned int port, Synchronizeable& sync, NodeType type)
-  : DataStream()
-{
+    : DataStream()
+{
+  this->type = type;
   this->init();
   this->networkSocket = new NetworkSocket();
-  this->networkSocket->listen(port);
+//  this->networkSocket->listen(port);
   this->networkProtocol = new NetworkProtocol();
   this->synchronizeables = &sync;
   this->connectionMonitor = new ConnectionMonitor();
+  this->bActive = true;
 }
 
@@ -79,4 +106,5 @@
   this->setClassID(CL_NETWORK_STREAM, "NetworkStream");
   this->state = NET_REC_HEADER;
+  this->bActive = false;
 }
 
@@ -85,12 +113,21 @@
 {
 
- networkSocket->disconnectServer();
-
- if( this->networkSocket)
-   delete networkSocket;
-
- delete connectionMonitor;
- delete networkProtocol;
-}
+  networkSocket->disconnectServer();
+
+  if( this->networkSocket)
+    delete networkSocket;
+
+  delete connectionMonitor;
+  delete networkProtocol;
+}
+
+
+void NetworkStream::connectSynchronizeable(Synchronizeable& sync)
+{
+  this->synchronizeables = &sync;
+  if( this->networkSocket != NULL)
+    this->bActive = true;
+}
+
 
 void NetworkStream::processData()
@@ -102,17 +139,23 @@
   PRINT(0)("============= DOWNSTREAM:===============\n");
   /* first of all read the synchronizeable's data: */
-  dataLength = this->synchronizeables->readBytes((byte*)downBuffer);
-
-  /* send the received data to connectionMonitor */
-  this->connectionMonitor->processPacket((byte*)downBuffer, dataLength);
-
-  dataLength = this->networkProtocol->createHeader((byte*)downBuffer, dataLength, DATA_STREAM_BUFFER_SIZE,
-      *(this->synchronizeables), 12/* some random number (no real id)*/);
-
-  /* pass the data to the network socket */
-  dataLength = this->networkSocket->writeBytes((byte*)downBuffer, dataLength);
-  /* check if there was an error */
-  if( dataLength == -1) { PRINTF(0)("Error in writing data to the NetworkSocket\n");}
-
+  if( this->isServer())
+    dataLength = this->synchronizeables->readBytes((byte*)downBuffer);
+
+  if( dataLength > 0)
+  {
+    /* send the received data to connectionMonitor */
+    this->connectionMonitor->processPacket((byte*)downBuffer, dataLength);
+
+    dataLength = this->networkProtocol->createHeader((byte*)downBuffer, dataLength, DATA_STREAM_BUFFER_SIZE,
+                 *(this->synchronizeables), 12/* some random number (no real id)*/);
+
+    /* pass the data to the network socket */
+ //   dataLength = this->networkSocket->writeBytes((byte*)downBuffer, dataLength);
+    /* check if there was an error */
+    if( dataLength == -1)
+    {
+      PRINTF(0)("Error in writing data to the NetworkSocket\n");
+    }
+  }
 
 
@@ -124,5 +167,5 @@
   if( this->state == NET_REC_HEADER)
   {
-    dataLength = this->networkSocket->readBlock((byte*)upBuffer, sizeof(Header));
+//    dataLength = this->networkSocket->readBlock((byte*)upBuffer, sizeof(Header));
     if( dataLength == sizeof(Header))
     {
@@ -139,13 +182,14 @@
   {
     /* now read the data */
-    dataLength = this->networkSocket->readBlock((byte*)upBuffer, this->packetHeader.length);
+//    dataLength = this->networkSocket->readBlock((byte*)upBuffer, this->packetHeader.length);
     /* check if the data is available and process it if so */
     if( dataLength == this->packetHeader.length)
     {
-      printf("NetworkStream::processData() - Got Data: \n");
+      printf("NetworkStream::processData() - Got Data: %i bytes\n", dataLength);
       /* send the received data to connectionMonitor */
       this->connectionMonitor->processPacket((byte*)upBuffer, this->packetHeader.length);
       /* now pass the data to the sync object */
-      this->synchronizeables->writeBytes((byte*)upBuffer, this->packetHeader.length);
+      if( !this->isServer())
+        this->synchronizeables->writeBytes((byte*)upBuffer, this->packetHeader.length);
 
       this->state = NET_REC_HEADER;
Index: branches/network/src/lib/network/network_stream.h
===================================================================
--- trunk/src/lib/network/network_stream.h	(revision 5995)
+++ branches/network/src/lib/network/network_stream.h	(revision 5999)
@@ -28,26 +28,30 @@
 {
 
-public:
-  NetworkStream();
-  NetworkStream(IPaddress& address, Synchronizeable& sync, NodeType type);
-  NetworkStream(unsigned int port, Synchronizeable& sync, NodeType type);
-  ~NetworkStream();
+  public:
+    NetworkStream();
+    NetworkStream(IPaddress& address, NodeType type);
+    NetworkStream(unsigned int port, NodeType type);
 
-  void init();
+    NetworkStream(IPaddress& address, Synchronizeable& sync, NodeType type);
+    NetworkStream(unsigned int port, Synchronizeable& sync, NodeType type);
+    ~NetworkStream();
+    void init();
 
-  inline bool isServer() { return (this->type == NET_SERVER)? true:false; }
-  virtual void processData();
+    void connectSynchronizeable(Synchronizeable& sync);
 
-private:
-   NetworkProtocol* networkProtocol;
-   //NetworkSocket*       networkSockets;
-   ConnectionMonitor*      connectionMonitor;
-   // tList<Synchronizeable>* synchronizeables;
-   Synchronizeable*         synchronizeables;
-   NetworkSocket* networkSocket;
-   int                    type;
-   int                    state;
-   Header                 packetHeader;
+    inline bool isServer() const { return (this->type == NET_SERVER)? true:false; }
+    inline bool isActive() const { return this->bActive; }
+
+    virtual void processData();
+
+  private:
+    NetworkProtocol*       networkProtocol;
+    ConnectionMonitor*     connectionMonitor;
+    Synchronizeable*       synchronizeables;
+    NetworkSocket*         networkSocket;
+    int                    type;
+    int                    state;
+    Header                 packetHeader;
+    bool                   bActive;
 };
 #endif /* _NETWORK_STREAM */
-
Index: branches/network/src/lib/network/server_socket.cc
===================================================================
--- branches/network/src/lib/network/server_socket.cc	(revision 5999)
+++ branches/network/src/lib/network/server_socket.cc	(revision 5999)
@@ -0,0 +1,125 @@
+/*
+   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: Christoph Renner
+   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 your own header */
+#include "server_socket.h"
+
+/* header for debug output */
+#include "debug.h"
+
+ServerSocket::ServerSocket(  )
+{
+  init();
+}
+
+ServerSocket::ServerSocket( unsigned int port )
+{
+  init();
+  listen(port);
+}
+
+/**
+ * Default destructor
+ */
+ServerSocket::~ServerSocket( )
+{
+  /* Quit SDL_net */
+  // NOTE: what if other instances of NetworkSocket running?
+  SDLNet_Quit();
+  PRINTF(5)("SDL_net shutdown\n");
+
+  _isListening = false;
+}
+
+void ServerSocket::init( )
+{
+  /* set the class id for the base object */
+  this->setClassID(CL_SERVER_SOCKET, "ServerSocket");
+
+  terminateThread = false;
+  listenSocket = NULL;
+  _isListening = false;
+
+  if(SDLNet_Init()==-1)
+  {
+    PRINTF(1)("SDLNet_Init: %s\n", SDLNet_GetError());
+    return;
+  }
+  else
+    PRINTF(5)("SDL_net initialized\n");
+
+  PRINTF(0)("ServerSocket created\n");
+}
+
+
+/**
+ * Tells the NetworkSocket to listen on a specific port for incoming connections.
+ * NetworkSocket::writeBytes(...) will have no effect until there is a valuable connection.
+ * @param port
+ */
+bool ServerSocket::listen(unsigned int port)
+{
+  PRINTF(0)("ServerSocket::listen()\n");
+  _isListening = true;
+  //check if not already connected or listening
+  if (listenSocket)
+  {
+    PRINTF(1)("ServerSocket::listen: tcpSocket!=NULL! maybe you already called listen or did not call close()!\n");
+    _isListening = false;
+    return false;
+  }
+
+  IPaddress ip;
+
+  if (SDLNet_ResolveHost(&ip, NULL, port)==-1)
+  {
+    PRINTF(1)("SDLNet_ResolveHost: %s\n", SDLNet_GetError());
+    _isListening = false;
+    return false;
+  }
+
+  listenSocket = SDLNet_TCP_Open(&ip);
+
+  if (!listenSocket)
+  {
+    PRINTF(1)("SDLNet_TCP_Open: %s\n", SDLNet_GetError());
+    _isListening = false;
+    return false;
+  }
+
+  return true;
+}
+
+
+NetworkSocket ServerSocket::getNewSocket( )
+{
+  TCPsocket sock = SDLNet_TCP_Accept(listenSocket);
+
+  if ( !sock )
+  {
+    return NULL;
+  }
+  else
+  {
+    return NetworkSocket(sock);
+  }
+}
+
Index: branches/network/src/lib/network/server_socket.h
===================================================================
--- branches/network/src/lib/network/server_socket.h	(revision 5999)
+++ branches/network/src/lib/network/server_socket.h	(revision 5999)
@@ -0,0 +1,44 @@
+/*!
+ * @file server_socket.h
+ *  waits for incoming connections
+
+ */
+
+#ifndef _SERVER_SOCKET
+#define _SERVER_SOCKET
+
+#ifdef HAVE_SDL_H
+#include <SDL_thread.h>
+#else
+#include <SDL/SDL_thread.h>
+#endif
+/* include this file, it contains some default definitions */
+#include "netdefs.h"
+
+
+/* include base_object.h since all classes are derived from this one */
+#include "base_object.h"
+#include "network_socket.h"
+
+//sleep when waiting for connections
+#define _MSECONDS_SLEEP_LISTEN 100
+
+class ServerSocket : public BaseObject
+{
+  private:
+    TCPsocket listenSocket;
+    bool terminateThread;
+
+    bool _isListening;
+
+    void init();
+
+  public:
+    ServerSocket();
+    ServerSocket( unsigned int port );
+    ~ServerSocket();
+    bool listen( unsigned int port );
+    NetworkSocket getNewSocket( void );
+};
+
+#endif
Index: branches/network/src/lib/network/synchronizeable.cc
===================================================================
--- trunk/src/lib/network/synchronizeable.cc	(revision 5995)
+++ branches/network/src/lib/network/synchronizeable.cc	(revision 5999)
@@ -12,9 +12,22 @@
 ### File Specific:
    main-programmer: Silvan Nellen
-   co-programmer: ...
+   co-programmer: Benjamin Wuest
 */
 
 #include "synchronizeable.h"
 #include "netdefs.h"
+
+
+/**
+ *  default constructor
+ */
+Synchronizeable::Synchronizeable()
+{
+
+  //owner = ?;
+  //hostID = ?;
+  //state = ?;
+
+}
 
 /**
@@ -25,4 +38,5 @@
   this->setName(name);
 }
+
 
 /**
@@ -41,5 +55,5 @@
  *  read data from NetworkStream
  */
-int Synchronizeable::readBytes(byte* data) const
+int Synchronizeable::readBytes(byte* data)
 {}
 
@@ -51,2 +65,48 @@
 void Synchronizeable::readDebug() const
 {}
+
+
+
+
+
+/**
+ * Sets the server flag to a given value
+ * @param isServer: the boolean value which the server flag is to set to
+ */
+void Synchronizeable::setIsServer(bool isServer)
+{
+  if( isServer )
+    this->state = this->state | STATE_SERVER;
+  else
+    this->state = this->state & (~STATE_SERVER);
+}
+
+/**
+ * Sets the outofsync flag to a given value
+ * @param outOfSync: the boolean value which the outofsync flag is to set to
+ */
+void Synchronizeable::setIsOutOfSync(bool outOfSync)
+{
+  if( outOfSync )
+    this->state = this->state | STATE_OUTOFSYNC;
+  else
+    this->state = this->state & (~STATE_OUTOFSYNC);
+}
+
+/**
+ * Determines if the server flag is set
+ * @return true, if the server flag is true, false else
+ */
+bool Synchronizeable::isServer()
+{
+  return this->state & STATE_SERVER == STATE_SERVER;
+}
+
+/**
+ * Determines if the outofsync flag is set
+ * @return true, if the outofsync flag is true, false else
+ */
+bool Synchronizeable::isOutOfSync()
+{
+  return this->state & STATE_OUTOFSYNC == STATE_OUTOFSYNC;
+}
Index: branches/network/src/lib/network/synchronizeable.h
===================================================================
--- trunk/src/lib/network/synchronizeable.h	(revision 5995)
+++ branches/network/src/lib/network/synchronizeable.h	(revision 5999)
@@ -7,6 +7,16 @@
 #define _SYNCHRONIZEABLE_H
 
-#include <base_object.h>
+#include "base_object.h"
 #include "netdefs.h"
+
+
+
+#include <vector>
+#include <list>
+
+//State constants: They have to be of the form 2^n
+#define STATE_SERVER 1
+#define STATE_OUTOFSYNC 2
+
 
 class Synchronizeable : virtual public BaseObject
@@ -15,14 +25,32 @@
 
     Synchronizeable(const char* name);
+    Synchronizeable();
     ~Synchronizeable();
 
     virtual void      writeBytes(const byte* data, int length);
-    virtual int       readBytes(byte* data) const;
+    virtual int       readBytes(byte* data);
     virtual void      writeDebug() const;
     virtual void      readDebug() const;
+    
+    
+    
+    
+    
+    void setIsServer(bool isServer);
+    void setIsOutOfSync(bool outOfSync);
+    bool isServer();
+    bool isOutOfSync();
 
   private:
 
     int               uniqueID;
+    
+    
+    
+    //static std::vector<Synchronizeable*> classList;
+    int owner;
+    int hostID;
+    int state;
+    std::list<int> synchronizeRequests;
 
   };
Index: branches/network/src/lib/sound/sound_engine.cc
===================================================================
--- trunk/src/lib/sound/sound_engine.cc	(revision 5995)
+++ branches/network/src/lib/sound/sound_engine.cc	(revision 5999)
@@ -289,4 +289,5 @@
   }
   // INITIALIZING THE DEVICE:
+
 #ifdef AL_VERSION_1_1
   ALubyte deviceName[] =
@@ -294,4 +295,5 @@
   ALCchar deviceName[] =
 #endif
+
 #ifdef __WIN32__
       "Direct3D";
@@ -304,5 +306,5 @@
   this->context = alcCreateContext(this->device, NULL);
 
-  alcMakeContextCurrent(this->context); 
+  alcMakeContextCurrent(this->context);
 
   if ((result = alGetError()) != AL_NO_ERROR)
Index: branches/network/src/orxonox.cc
===================================================================
--- trunk/src/orxonox.cc	(revision 5995)
+++ branches/network/src/orxonox.cc	(revision 5999)
@@ -57,4 +57,6 @@
 #include "load_param_description.h"
 
+#include "network_manager.h"
+
 #include <string.h>
 
@@ -79,4 +81,8 @@
   this->argc = 0;
   this->argv = NULL;
+
+  /* this way, there is no network enabled: */
+  this->serverName = NULL;
+  this->port = -1;
 
   this->configFileName = NULL;
@@ -118,11 +124,11 @@
 
   PRINT(3)
-      (
-      "===================================================\n" \
-      "Thanks for playing orxonox.\n" \
-      "visit: http://www.orxonox.net for new versions.\n" \
-      "===================================================\n" \
-      ORXONOX_LICENSE_SHORT
-      );
+  (
+    "===================================================\n" \
+    "Thanks for playing orxonox.\n" \
+    "visit: http://www.orxonox.net for new versions.\n" \
+    "===================================================\n" \
+    ORXONOX_LICENSE_SHORT
+  );
 
   Orxonox::singletonRef = NULL;
@@ -137,21 +143,21 @@
 void Orxonox::restart()
 {
-//   int argc = this->argc;
-//   char** argv = this->argv;
-//
-//   Orxonox *orx = Orxonox::getInstance();
-//
-//   delete orx;
-//
-//   orx = Orxonox::getInstance();
-//
-//   if((*orx).init(argc, argv) == -1)
-//   {
-//     PRINTF(1)("! Orxonox initialization failed\n");
-//     return;
-//   }
-//
-//   printf("finished inizialisation\n");
-//   orx->start();
+  //   int argc = this->argc;
+  //   char** argv = this->argv;
+  //
+  //   Orxonox *orx = Orxonox::getInstance();
+  //
+  //   delete orx;
+  //
+  //   orx = Orxonox::getInstance();
+  //
+  //   if((*orx).init(argc, argv) == -1)
+  //   {
+  //     PRINTF(1)("! Orxonox initialization failed\n");
+  //     return;
+  //   }
+  //
+  //   printf("finished inizialisation\n");
+  //   orx->start();
 }
 
@@ -179,16 +185,15 @@
  * initialize Orxonox with command line
  */
-int Orxonox::init (int argc, char** argv)
+int Orxonox::init (int argc, char** argv, const char* name, int port)
 {
   this->argc = argc;
   this->argv = argv;
-  // parse command line
-  // config file
+
+  this->serverName = name;
+  this->port = port;
 
   // initialize the Config-file
   this->getConfigFile();
 
-  // initialize everything
-  SDL_Init(SDL_INIT_TIMER);
   // windows must not write into stdout.txt and stderr.txt
 #ifdef __WIN32__
@@ -197,17 +202,26 @@
 #endif
 
-  if( initResources () == -1) return -1;
-  if( initVideo() == -1) return -1;
-  if( initSound() == -1) return -1;
-  if( initInput() == -1) return -1;
-  if( initNetworking () == -1) return -1;
-  if( initMisc () == -1) return -1;
-
-  return 0;
-}
+  // initialize everything
+  SDL_Init(SDL_INIT_TIMER);
+  if( initResources () == -1)
+    return -1;
+  if( initVideo() == -1)
+    return -1;
+  if( initSound() == -1)
+    return -1;
+  if( initInput() == -1)
+    return -1;
+  if( initNetworking () == -1)
+    return -1;
+  if( initMisc () == -1)
+    return -1;
+
+  return 0;
+}
+
 
 /**
  * initializes SDL and OpenGL
-*/
+ */
 int Orxonox::initVideo()
 {
@@ -226,4 +240,5 @@
   return 0;
 }
+
 
 /**
@@ -263,5 +278,9 @@
   PRINT(3)("> Initializing networking\n");
 
-  printf("  ---Not yet implemented-FIXME--\n");
+  if( this->serverName != NULL) // we are a client
+    NetworkManager::getInstance()->establishConnection(this->serverName, port);
+  else if( this->port > 0)      // we are a server
+    NetworkManager::getInstance()->createServer(port);
+
   return 0;
 }
@@ -282,5 +301,5 @@
   {
     if (!ResourceManager::getInstance()->setDataDir(dataPath) &&
-         !ResourceManager::getInstance()->verifyDataDir(DEFAULT_DATA_DIR_CHECKFILE))
+        !ResourceManager::getInstance()->verifyDataDir(DEFAULT_DATA_DIR_CHECKFILE))
     {
       PRINTF(1)("Data Could not be located in %s\n", dataPath);
@@ -301,5 +320,5 @@
     exit(-1);
   }
-   //! @todo this is a hack and should be loadable
+  //! @todo this is a hack and should be loadable
   char* imageDir = ResourceManager::getInstance()->getFullName("maps");
   ResourceManager::getInstance()->addImageDir(imageDir);
@@ -332,5 +351,10 @@
 
   this->gameLoader = GameLoader::getInstance();
-  this->gameLoader->loadCampaign("worlds/DefaultCampaign.oxc");
+
+  if( this->port != -1 || this->serverName != NULL)
+    this->gameLoader->loadCampaign("worlds/DefaultCampaign.oxc"); /* actualy loadNetworkCampaign*/
+  else
+    this->gameLoader->loadCampaign("worlds/DefaultCampaign.oxc");
+
   //  this->gameLoader->loadDebugCampaign(DEBUG_CAMPAIGN_0);
   this->gameLoader->init();
@@ -375,31 +399,94 @@
 int main(int argc, char** argv)
 {
-  // here the pre-arguments are loaded, these are needed to go either to orxonx itself, Help, or Benchmark.
   int i;
   for(i = 1; i < argc; ++i)
+  {
+    if(     !strcmp( "--help", argv[i])     || !strcmp("-h", argv[i]))
+      return showHelp(argc, argv);
+    else if(!strcmp( "--gui", argv[i])      || !strcmp("-g", argv[i]))
+      showGui = true;
+    else if(!strcmp( "--client", argv[i])   || !strcmp("-c", argv[i]))
+      return startNetworkOrxonox(argc, argv);
+    else if(!strcmp( "--server", argv[i])   || !strcmp("-s", argv[i]))
+      return startNetworkOrxonox(argc, argv);
+    else if(!strcmp( "--license", argv[i])  || !strcmp("-s", argv[i]))
+      return PRINT(0)(ORXONOX_LICENSE_SHORT);
+  }
+
+  return startOrxonox(argc, argv, NULL, -1);
+}
+
+
+
+int showHelp(int argc, char** argv)
+{
+  PRINT(0)("Orxonox Version %s\n", PACKAGE_VERSION);
+  PRINT(0)(" Starts Orxonox - The most furious 3D Action Game :)\n");
+  PRINT(0)("\n");
+  PRINT(0)("Common options:\n");
+  PRINT(0)(" -g, --gui                        starts the orxonox with the configuration GUI \n");
+  PRINT(0)(" -h, --help                       shows this help\n");
+  PRINT(0)("\n");
+  PRINT(0)("Network options:\n");
+  PRINT(0)(" -s, --server [port]              starts Orxonox and listens on the [port] for players\n");
+  PRINT(0)(" -c, --client [hostname] [port]   starts Orxonox as a Client\n");
+  PRINT(0)(" -c, --client [ip address] [port] starts Orxonox as a Client\n");
+  PRINT(0)("\n");
+  PRINT(0)("Other options:\n");
+  PRINT(0)("     --license     prints the licence and exit\n\n");
+  PRINT(0)("\n");
+
+  //   {
+  //     Gui* gui = new Gui(argc, argv);
+  //     gui->printHelp();
+  //     delete gui;
+  //   }
+}
+
+
+
+
+/**
+ * starts orxonox in network mode
+ * @param argc parameters count given to orxonox
+ * @param argv parameters given to orxonox
+ */
+int startNetworkOrxonox(int argc, char** argv)
+{
+
+  int i;
+  for(i = 0; i < argc; ++i )
+  {
+    if( !strcmp( "--client", argv[i]) || !strcmp("-c", argv[i]))
     {
-      if(! strcmp( "--help", argv[i]) || !strcmp("-h", argv[i])) return startHelp(argc, argv);
-//      else if(!strcmp( "--benchmark", argv[i]) || !strcmp("-b", argv[i])) return startBenchmarks();
-      else if(!strcmp( "--gui", argv[i]) || !strcmp("-g", argv[i])) showGui = true;
-      //      else PRINTF(2)("Orxonox does not understand the arguments %s\n", argv[i]);
+      if( argc <= (i+2))
+      {
+        printf(" Wrong arguments try following notations:\n");
+        printf("   --client [server ip address] [port number]\n");
+        printf("   --client [dns name] [port number]\n");
+        return 0;
+      }
+
+      const char* name = argv[i+1];
+      int port = atoi(argv[i+2]);
+      printf("Starting Orxonox as client: connecting to %s, on port %i\n", name, port);
+
+      startOrxonox(argc, argv, name, port);
     }
-
-  return startOrxonox(argc, argv);
-}
-
-
-
-int startHelp(int argc, char** argv)
-{
-  PRINT(0)("orxonox: starts the orxonox game - rules\n");
-  PRINT(0)("usage: orxonox [arg [arg...]]\n\n");
-  PRINT(0)("valid options:\n");
-  {
-    Gui* gui = new Gui(argc, argv);
-    gui->printHelp();
-    delete gui;
-  }
-  PRINT(0)(" -b|--benchmark:\t\tstarts the orxonox benchmark\n");
-  PRINT(0)(" -h|--help:\t\t\tshows this help\n");
+    else if( !strcmp( "--server", argv[i]) || !strcmp("-s", argv[i]))
+    {
+      if( argc <= (i+1))
+      {
+        printf(" Wrong arguments try following notations:\n");
+        printf("   --server [port number]\n");
+        return 0;
+      }
+
+      int port = atoi(argv[i+1]);
+      printf("Starting Orxonox as server, listening on port %i\n", port);
+
+      startOrxonox(argc, argv, NULL, port);
+    }
+  }
 }
 
@@ -411,26 +498,26 @@
  * @param argv parameters given to orxonox
  */
-int startOrxonox(int argc, char** argv)
+int startOrxonox(int argc, char** argv, const char* name, int port)
 {
   // checking for existence of the configuration-files, or if the lock file is still used
   if (showGui || (!ResourceManager::isFile("./orxonox.conf") &&
-      !ResourceManager::isFile(DEFAULT_CONFIG_FILE))
+                  !ResourceManager::isFile(DEFAULT_CONFIG_FILE))
 #if DEBUG < 3 // developers do not need to see the GUI, when orxonox fails
-       || ResourceManager::isFile(DEFAULT_LOCK_FILE)
+      || ResourceManager::isFile(DEFAULT_LOCK_FILE)
 #endif
      )
-    {
-      if (ResourceManager::isFile(DEFAULT_LOCK_FILE))
-        ResourceManager::deleteFile(DEFAULT_LOCK_FILE);
-
-      // starting the GUI
-      Gui* gui = new Gui(argc, argv);
-      gui->startGui();
-
-      if (! gui->startOrxonox)
-        return 0;
-
-      delete gui;
-    }
+  {
+    if (ResourceManager::isFile(DEFAULT_LOCK_FILE))
+      ResourceManager::deleteFile(DEFAULT_LOCK_FILE);
+
+    // starting the GUI
+    Gui* gui = new Gui(argc, argv);
+    gui->startGui();
+
+    if (! gui->startOrxonox)
+      return 0;
+
+    delete gui;
+  }
 
   PRINT(0)(">>> Starting Orxonox <<<\n");
@@ -440,11 +527,11 @@
   Orxonox *orx = Orxonox::getInstance();
 
-  if(orx->init(argc, argv) == -1)
-    {
-      PRINTF(1)("! Orxonox initialization failed\n");
-      return -1;
-    }
-
-    printf("finished inizialisation\n");
+  if( orx->init(argc, argv, name, port) == -1)
+  {
+    PRINTF(1)("! Orxonox initialization failed\n");
+    return -1;
+  }
+
+  printf("finished inizialisation\n");
   orx->start();
 
Index: branches/network/src/orxonox.h
===================================================================
--- trunk/src/orxonox.h	(revision 5995)
+++ branches/network/src/orxonox.h	(revision 5999)
@@ -23,11 +23,9 @@
   inline static Orxonox* getInstance() { if (!singletonRef) singletonRef = new Orxonox();  return singletonRef; };
 
-  int init (int argc, char** argv);
+  int init(int argc, char** argv, const char* name, int port);
 
   void restart();
 
   void start();
-
-  //void graphicsHandler (SDL_Event* event);
 
  private:
@@ -43,5 +41,4 @@
   int initMisc ();
 
-
   const char* getConfigFile ();
 
@@ -55,4 +52,7 @@
   unsigned int      argc;                    //!< Count of Arguments of orxonox
   char**            argv;                    //!< Values of th Arguments of orxonox.
+
+  const char*       serverName;              //!< Name of the Orxonox client if == NULL -> server
+  int               port;                    //!< number of the network port of the server/client if == -1 no network
 };
 
@@ -61,6 +61,8 @@
 // Start-up functions //
 ////////////////////////
-int startHelp(int argc, char** argv);
-int startOrxonox(int argc, char** argv);
+int showHelp(int argc, char** argv);
+int showLicense();
+int startNetworkOrxonox(int argc, char** argv);
+int startOrxonox(int argc, char** argv, const char* clientName, int port);
 
 #endif /* _ORXONOX_H */
Index: branches/network/src/story_entities/world.cc
===================================================================
--- trunk/src/story_entities/world.cc	(revision 5995)
+++ branches/network/src/story_entities/world.cc	(revision 5999)
@@ -71,4 +71,7 @@
 
 #include "playable.h"
+#include "network_manager.h"
+#include "playable.h"
+
 
 SHELL_COMMAND(speed, World, setSpeed);
@@ -317,10 +320,10 @@
       while( element != NULL)
         {
-          BaseObject* created = (Factory::fabricate(element));
+          BaseObject* created = Factory::fabricate(element);
           if( created != NULL )
           {
             if(created->isA(CL_WORLD_ENTITY))
               this->spawn(dynamic_cast<WorldEntity*>(created));
-            PRINTF(4)("Created a %s: %s\n", created->getClassName(), created->getName());
+            printf("Created a %s: %s\n", created->getClassName(), created->getName());
           }
 
@@ -659,4 +662,5 @@
   // Get remote input
   // Update synchronizables
+/*  NetworkManager::getInstance()->synchronize();*/
 }
 
Index: branches/network/src/subprojects/network/Makefile.am
===================================================================
--- trunk/src/subprojects/network/Makefile.am	(revision 5995)
+++ branches/network/src/subprojects/network/Makefile.am	(revision 5999)
@@ -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: branches/network/src/subprojects/network/network_unit_test.cc
===================================================================
--- trunk/src/subprojects/network/network_unit_test.cc	(revision 5995)
+++ branches/network/src/subprojects/network/network_unit_test.cc	(revision 5999)
@@ -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: branches/network/src/subprojects/network/read_sync.cc
===================================================================
--- branches/network/src/subprojects/network/read_sync.cc	(revision 5999)
+++ branches/network/src/subprojects/network/read_sync.cc	(revision 5999)
@@ -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: branches/network/src/subprojects/network/read_sync.h
===================================================================
--- branches/network/src/subprojects/network/read_sync.h	(revision 5999)
+++ branches/network/src/subprojects/network/read_sync.h	(revision 5999)
@@ -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: branches/network/src/subprojects/network/simple_sync.cc
===================================================================
--- trunk/src/subprojects/network/simple_sync.cc	(revision 5995)
+++ branches/network/src/subprojects/network/simple_sync.cc	(revision 5999)
@@ -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: branches/network/src/subprojects/network/simple_sync.h
===================================================================
--- trunk/src/subprojects/network/simple_sync.h	(revision 5995)
+++ branches/network/src/subprojects/network/simple_sync.h	(revision 5999)
@@ -17,5 +17,5 @@
 
     virtual void writeBytes(const byte* data, int length);
-    virtual int readBytes(byte* data) const;
+    virtual int readBytes(byte* data);
 
 
Index: branches/network/src/subprojects/network/write_sync.cc
===================================================================
--- branches/network/src/subprojects/network/write_sync.cc	(revision 5999)
+++ branches/network/src/subprojects/network/write_sync.cc	(revision 5999)
@@ -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: branches/network/src/subprojects/network/write_sync.h
===================================================================
--- branches/network/src/subprojects/network/write_sync.h	(revision 5999)
+++ branches/network/src/subprojects/network/write_sync.h	(revision 5999)
@@ -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 */
Index: branches/network/src/world_entities/space_ships/space_ship.h
===================================================================
--- trunk/src/world_entities/space_ships/space_ship.h	(revision 5995)
+++ branches/network/src/world_entities/space_ships/space_ship.h	(revision 5999)
@@ -1,2 +1,3 @@
+
 /*!
  * @file space_ship.h
@@ -57,5 +58,5 @@
     bool                  bRollL;             //!< rolling button pressed (left)
     bool                  bRollR;             //!< rolling button pressed (right)
-    
+
     float                 xMouse;             //!< mouse moved in x-Direction
     float                 yMouse;             //!< mouse moved in y-Direction
Index: branches/network/src/world_entities/world_entity.cc
===================================================================
--- trunk/src/world_entities/world_entity.cc	(revision 5995)
+++ branches/network/src/world_entities/world_entity.cc	(revision 5999)
@@ -41,4 +41,5 @@
  */
 WorldEntity::WorldEntity(const TiXmlElement* root)
+  : Synchronizeable()
 {
   this->setClassID(CL_WORLD_ENTITY, "WorldEntity");
Index: branches/network/src/world_entities/world_entity.h
===================================================================
--- trunk/src/world_entities/world_entity.h	(revision 5995)
+++ branches/network/src/world_entities/world_entity.h	(revision 5999)
@@ -8,4 +8,6 @@
 
 #include "p_node.h"
+#include "synchronizeable.h"
+#include "model.h"
 
 #include "glincl.h"
@@ -22,5 +24,5 @@
 
 //! Basis-class all interactive stuff in the world is derived from
-class WorldEntity : public PNode
+class WorldEntity : public PNode, public Synchronizeable
 {
  public:
