Index: branches/network/src/lib/network/network_manager.cc
===================================================================
--- branches/network/src/lib/network/network_manager.cc	(revision 5824)
+++ branches/network/src/lib/network/network_manager.cc	(revision 5829)
@@ -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);
+}
+
 
 /**
@@ -161,7 +157,18 @@
   if (this->netStreamList != NULL || (this->netStreamList = ClassList::getList(CL_NETWORK_STREAM)) != NULL)
   {
+//     tIterator<BaseObject>* iterator = this->netStreamList->getIterator();
+//     NetworkStream* stream = (NetworkStream*)(iterator->firstElement());
+//     while( stream)
+//     {
+//       if(stream->isActive())
+//         stream->processData();
+//       stream = (NetworkStream*)(iterator->nextElement());
+//     }
+//     delete iterator;
     std::list<BaseObject*>::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: branches/network/src/lib/network/network_manager.h
===================================================================
--- branches/network/src/lib/network/network_manager.h	(revision 5824)
+++ branches/network/src/lib/network/network_manager.h	(revision 5829)
@@ -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,33 @@
 {
 
-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:
-  std::list<BaseObject*>*    netStreamList;            // list with refs to all network streams
-  std::list<BaseObject*>*    syncList;                 // list of synchronizeables
+    void connectSynchronizeable(Synchronizeable& sync);
+
+    void synchronize();
+
+  private:
+    NetworkManager();
+
+
+  private:
+    std::list<BaseObject*>*    netStreamList;            // list with refs to all network streams
+    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: branches/network/src/lib/network/network_socket.cc
===================================================================
--- branches/network/src/lib/network/network_socket.cc	(revision 5824)
+++ branches/network/src/lib/network/network_socket.cc	(revision 5829)
@@ -313,5 +313,8 @@
 
   while (!tempsocket && !self->terminateThread)
+  {
     tempsocket = SDLNet_TCP_Accept(self->tcpSocket);
+    SDL_Delay(_MSECONDS_SLEEP_LISTEN);
+  }
 
   SDL_mutexP(self->socketMutex);
Index: branches/network/src/lib/network/network_socket.h
===================================================================
--- branches/network/src/lib/network/network_socket.h	(revision 5824)
+++ branches/network/src/lib/network/network_socket.h	(revision 5829)
@@ -18,4 +18,6 @@
 //sleep if outgoing buffer is empty
 #define _MSECONDS_SLEEP_EMPTY_BUFFER 10
+//sleep when waiting for connections
+#define _MSECONDS_SLEEP_LISTEN 100
 
 /* contains memmove and memcpy */
Index: branches/network/src/lib/network/network_stream.cc
===================================================================
--- branches/network/src/lib/network/network_stream.cc	(revision 5824)
+++ branches/network/src/lib/network/network_stream.cc	(revision 5829)
@@ -40,5 +40,5 @@
 
 NetworkStream::NetworkStream()
-  : DataStream()
+    : DataStream()
 {
   this->init();
@@ -50,7 +50,27 @@
 }
 
+NetworkStream::NetworkStream(IPaddress& address, NodeType 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->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->init();
@@ -59,9 +79,10 @@
   this->synchronizeables = &sync;
   this->connectionMonitor = new ConnectionMonitor();
+  this->bActive = true;
 }
 
 
 NetworkStream::NetworkStream(unsigned int port, Synchronizeable& sync, NodeType type)
-  : DataStream()
+    : DataStream()
 {
   this->init();
@@ -71,4 +92,5 @@
   this->synchronizeables = &sync;
   this->connectionMonitor = new ConnectionMonitor();
+  this->bActive = true;
 }
 
@@ -79,4 +101,5 @@
   this->setClassID(CL_NETWORK_STREAM, "NetworkStream");
   this->state = NET_REC_HEADER;
+  this->bActive = false;
 }
 
@@ -85,12 +108,21 @@
 {
 
- networkSocket->disconnectServer();
+  networkSocket->disconnectServer();
 
- if( this->networkSocket)
-   delete networkSocket;
+  if( this->networkSocket)
+    delete networkSocket;
 
- delete connectionMonitor;
- delete networkProtocol;
+  delete connectionMonitor;
+  delete networkProtocol;
 }
+
+
+void NetworkStream::connectSynchronizeable(Synchronizeable& sync)
+{
+  this->synchronizeables = &sync;
+  if( this->networkSocket != NULL)
+    this->bActive = true;
+}
+
 
 void NetworkStream::processData()
@@ -102,17 +134,23 @@
   PRINT(0)("============= DOWNSTREAM:===============\n");
   /* first of all read the synchronizeable's data: */
+  //if(this->isServer())
   dataLength = this->synchronizeables->readBytes((byte*)downBuffer);
 
-  /* send the received data to connectionMonitor */
-  this->connectionMonitor->processPacket((byte*)downBuffer, dataLength);
+  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)*/);
+    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");}
-
+    /* 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");
+    }
+  }
 
 
@@ -147,4 +185,5 @@
       this->connectionMonitor->processPacket((byte*)upBuffer, this->packetHeader.length);
       /* now pass the data to the sync object */
+      //if(!this->isServer())
       this->synchronizeables->writeBytes((byte*)upBuffer, this->packetHeader.length);
 
Index: branches/network/src/lib/network/network_stream.h
===================================================================
--- branches/network/src/lib/network/network_stream.h	(revision 5824)
+++ branches/network/src/lib/network/network_stream.h	(revision 5829)
@@ -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/synchronizeable.cc
===================================================================
--- branches/network/src/lib/network/synchronizeable.cc	(revision 5824)
+++ branches/network/src/lib/network/synchronizeable.cc	(revision 5829)
@@ -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: branches/network/src/lib/network/synchronizeable.h
===================================================================
--- branches/network/src/lib/network/synchronizeable.h	(revision 5824)
+++ branches/network/src/lib/network/synchronizeable.h	(revision 5829)
@@ -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;
