Index: branches/network/src/subprojects/network/network_unit_test.cc
===================================================================
--- branches/network/src/subprojects/network/network_unit_test.cc	(revision 5968)
+++ branches/network/src/subprojects/network/network_unit_test.cc	(revision 5987)
@@ -8,4 +8,5 @@
 #include "network_manager.h"
 #include "network_socket.h"
+#include "server_socket.h"
 #include "network_stream.h"
 #include "synchronizeable.h"
@@ -36,85 +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;
