Fixed split packages bug.
[clanbomber-xamarin-client.git] / src / communication / ConnectionTest / ServerSimulator / Program.cs
index 9334aa8..7a724e2 100644 (file)
@@ -253,7 +253,7 @@ namespace ServerSimulator
             Socket listener;
 
             IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());
-            IPAddress ipAddress = ipHostInfo.AddressList[0];
+            IPAddress ipAddress = ipHostInfo.AddressList[1];
             IPEndPoint localEndPoint = new IPEndPoint(ipAddress, m_gameSimulation.c_ServerPort);
 
             // Create a TCP/IP socket.  
@@ -329,9 +329,20 @@ namespace ServerSimulator
                                 string msgWithRestFromPrecedingMsg = restFromPreviousReception + data;
                                 recvPkgs = msgWithRestFromPrecedingMsg.Split('\0');
                                 restFromPreviousReception = "";
-                                if(recvPkgs[recvPkgs.Length-1] != "")
+                                if(recvPkgs[recvPkgs.Length-1] != "" + char.MinValue)
                                 {
                                     restFromPreviousReception = recvPkgs[recvPkgs.Length - 1];
+                                    string[] recvPkgsWithoutIncomplete = new string[recvPkgs.Length-1];
+                                    for (int i = 0; i < recvPkgs.Length-1; i++)
+                                    {
+                                        recvPkgsWithoutIncomplete[i] = recvPkgs[i];
+                                        
+                                    }
+                                    recvPkgs = recvPkgsWithoutIncomplete;
+                                    if (restFromPreviousReception != "")
+                                    {
+                                        Print("Incomplete MSG: " + restFromPreviousReception);
+                                    }
                                 }
 
                                 break;
@@ -343,7 +354,7 @@ namespace ServerSimulator
                     // Show the data on the console and forward to handler
                     for (int i = 0; i < recvPkgs.Length; i++)
                     {
-                        if (recvPkgs[i].Length > 0) // Filter '\0' strings..
+                        if (recvPkgs[i].Length > 0)
                         {                           
                             Print("Text received : " + recvPkgs[i]);
                             m_gameSimulation.HandleClientPackage(recvPkgs[i], GetClientId(handler));