Index: branches/network/src/lib/network/network_socket.cc
===================================================================
--- branches/network/src/lib/network/network_socket.cc	(revision 6024)
+++ branches/network/src/lib/network/network_socket.cc	(revision 6025)
@@ -28,4 +28,5 @@
 #include "debug.h"
 
+static SDL_mutex* threadTerminationMutex = SDL_CreateMutex();
 
 /**
@@ -65,6 +66,13 @@
   outgoingBufferLength = 0;
 
+#ifdef _USE_OUTGOING_BUFFER
+  thread_write_running = false;
+#endif
+  thread_read_running = false;
+
   incomingBufferMutex = SDL_CreateMutex();
   outgoingBufferMutex = SDL_CreateMutex();
+
+
   socketMutex = SDL_CreateMutex();
   terminateThread = false;
@@ -89,6 +97,7 @@
  * Default destructor
  */
-NetworkSocket::~ NetworkSocket( )
-{
+NetworkSocket::~NetworkSocket( )
+{
+  this->terminateThread = true;
   /* Quit SDL_net */
   // NOTE: what if other instances of NetworkSocket running?
@@ -275,5 +284,6 @@
     if (nbytesread<=0)
     {
-      printf("SDLNet_TCP_Recv: %s\n", SDLNet_GetError());
+      if (nbytesread<0)
+        printf("SDLNet_TCP_Recv: %s\n", SDLNet_GetError());
 
       SDL_mutexP(self->socketMutex);
@@ -295,4 +305,12 @@
   }
 
+  SDL_mutexP(threadTerminationMutex);
+  self->thread_read_running = false;
+
+  if ( !self->thread_write_running )
+    delete self;
+  SDL_mutexV(threadTerminationMutex);
+
+  printf("QUIT READ THREAD\n");
   return 0;
 }
@@ -347,4 +365,11 @@
   }
 
+  SDL_mutexP(threadTerminationMutex);
+  self->thread_write_running = false;
+
+  if ( !self->thread_read_running )
+    delete self;
+  SDL_mutexV(threadTerminationMutex);
+
   printf("QUIT WRITE THREAD\n");
   return 0;
Index: branches/network/src/lib/network/network_socket.h
===================================================================
--- branches/network/src/lib/network/network_socket.h	(revision 6024)
+++ branches/network/src/lib/network/network_socket.h	(revision 6025)
@@ -63,7 +63,10 @@
   bool terminateThread;
 
+  static SDL_mutex* threadTerminationMutex;
   static int thread_read(void * data);
+  bool thread_read_running;
 #ifdef _USE_OUTGOING_BUFFER
   static int thread_write(void * data);
+  bool thread_write_running;
 #endif
 
@@ -74,4 +77,7 @@
   void init();
 
+  //dont make this public use destroy() instead
+  ~NetworkSocket();
+
 public:
 
@@ -79,5 +85,6 @@
   NetworkSocket(IPaddress ip);
   NetworkSocket(TCPsocket sock);
-  ~NetworkSocket();
+  void destroy() { terminateThread = true; };
+
 
   void connectToServer(IPaddress ip);
Index: branches/network/src/lib/network/network_stream.cc
===================================================================
--- branches/network/src/lib/network/network_stream.cc	(revision 6024)
+++ branches/network/src/lib/network/network_stream.cc	(revision 6025)
@@ -93,5 +93,5 @@
     {
       (*i)->disconnectServer();
-      delete *i;
+      (*i)->destroy();
     }
   }
@@ -113,5 +113,5 @@
 void NetworkStream::processData()
 {
-  printf("processData()");
+  //PRINTF(0)("processData()\n");
   if ( this->type == NET_SERVER )
     this->updateConnectionList();
@@ -188,4 +188,5 @@
 {
   //check for new connections
+
   NetworkSocket* tempNetworkSocket = serverSocket->getNewSocket();
 
@@ -200,9 +201,9 @@
     } else
     {
+      clientId = networkSockets.size();
       networkSockets.push_back(tempNetworkSocket);
-      clientId = networkSockets.size();
-    }
-
-    PRINTF(0)("New Client: %s", clientId);
+    }
+
+    PRINTF(0)("New Client: %d\n", clientId);
     //TODO: start handshake
     //new Handshake(true, clientId);
@@ -216,6 +217,8 @@
     {
       //TODO: tell EntityManager that this player left the game
-
-      delete networkSockets[i];
+      PRINTF(0)("Client is gone: %d\n", i);
+
+      //delete networkSockets[i];
+      networkSockets[i]->destroy();
       networkSockets[i] = NULL;
 
@@ -231,3 +234,4 @@
   }
 
-}
+
+}
Index: branches/network/src/subprojects/network/network_unit_test.cc
===================================================================
--- branches/network/src/subprojects/network/network_unit_test.cc	(revision 6024)
+++ branches/network/src/subprojects/network/network_unit_test.cc	(revision 6025)
@@ -196,5 +196,5 @@
   {
     netMan->synchronize();
-    SDL_Delay(500);
+    SDL_Delay(1000);
   }
 
