Index: trunk/src/lib/network/Makefile.am
===================================================================
--- trunk/src/lib/network/Makefile.am	(revision 5885)
+++ trunk/src/lib/network/Makefile.am	(revision 5996)
@@ -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: trunk/src/lib/network/network_manager.cc
===================================================================
--- trunk/src/lib/network/network_manager.cc	(revision 5885)
+++ trunk/src/lib/network/network_manager.cc	(revision 5996)
@@ -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,5 @@
   this->netStreamList = NULL;
   this->syncList = NULL;
+  this->tmpStream = NULL;
 
   PRINTF(0)("NetworkManager created\n");
@@ -114,8 +84,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 +118,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 +131,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 +144,9 @@
 
 
+void NetworkManager::connectSynchronizeable(Synchronizeable& sync)
+{
+  this->tmpStream->connectSynchronizeable(sync);
+}
+
 
 /**
@@ -163,5 +159,7 @@
     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();
+
   }
 
Index: trunk/src/lib/network/network_manager.h
===================================================================
--- trunk/src/lib/network/network_manager.h	(revision 5885)
+++ trunk/src/lib/network/network_manager.h	(revision 5996)
@@ -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,35 @@
 {
 
-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 connectSynchronizeable(Synchronizeable& sync);
+    void synchronize();
+
+
+  private:
+    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
 
 };
Index: trunk/src/lib/network/network_socket.cc
===================================================================
--- trunk/src/lib/network/network_socket.cc	(revision 5885)
+++ trunk/src/lib/network/network_socket.cc	(revision 5996)
@@ -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: trunk/src/lib/network/network_socket.h
===================================================================
--- trunk/src/lib/network/network_socket.h	(revision 5885)
+++ trunk/src/lib/network/network_socket.h	(revision 5996)
@@ -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: trunk/src/lib/network/network_stream.cc
===================================================================
--- trunk/src/lib/network/network_stream.cc	(revision 5885)
+++ trunk/src/lib/network/network_stream.cc	(revision 5996)
@@ -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: trunk/src/lib/network/network_stream.h
===================================================================
--- trunk/src/lib/network/network_stream.h	(revision 5885)
+++ trunk/src/lib/network/network_stream.h	(revision 5996)
@@ -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: trunk/src/lib/network/server_socket.cc
===================================================================
--- trunk/src/lib/network/server_socket.cc	(revision 5996)
+++ trunk/src/lib/network/server_socket.cc	(revision 5996)
@@ -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: trunk/src/lib/network/server_socket.h
===================================================================
--- trunk/src/lib/network/server_socket.h	(revision 5996)
+++ trunk/src/lib/network/server_socket.h	(revision 5996)
@@ -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: trunk/src/lib/network/synchronizeable.cc
===================================================================
--- trunk/src/lib/network/synchronizeable.cc	(revision 5885)
+++ trunk/src/lib/network/synchronizeable.cc	(revision 5996)
@@ -18,4 +18,11 @@
 #include "netdefs.h"
 
+
+/**
+ *  default constructor
+ */
+Synchronizeable::Synchronizeable()
+{}
+
 /**
  *  default constructor
@@ -25,4 +32,5 @@
   this->setName(name);
 }
+
 
 /**
@@ -41,5 +49,5 @@
  *  read data from NetworkStream
  */
-int Synchronizeable::readBytes(byte* data) const
+int Synchronizeable::readBytes(byte* data)
 {}
 
Index: trunk/src/lib/network/synchronizeable.h
===================================================================
--- trunk/src/lib/network/synchronizeable.h	(revision 5885)
+++ trunk/src/lib/network/synchronizeable.h	(revision 5996)
@@ -15,8 +15,9 @@
 
     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;
