Fixed split packages bug.
authormile4712 <Lehner.Michael43@gmail.com>
Mon, 10 Dec 2018 09:40:38 +0000 (10:40 +0100)
committermile4712 <Lehner.Michael43@gmail.com>
Mon, 10 Dec 2018 09:40:38 +0000 (10:40 +0100)
Changed sockets from ipv6 to ipv4

src/communication/ConnectionTest/ConnectionTest/ConnectionTest/TcpJsonConnection.cs
src/communication/ConnectionTest/ServerSimulator/Program.cs
src/communication/ConnectionTest/TcpJsonConnectionTest/Program.cs

index 4f5693a..1e25467 100644 (file)
@@ -123,9 +123,20 @@ namespace ConnectionTest
                             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;
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));
index 867cd99..0b1bbbb 100644 (file)
@@ -15,9 +15,9 @@ namespace TcpJsonConnectionTest
         {
             TcpJsonConnection con = new TcpJsonConnection(DisplayServerInformation);
 
-            con.Connect(Dns.GetHostEntry(Dns.GetHostName()).AddressList[0]);    //localhost
-           // con.Connect(IPAddress.Parse("fe80::c0a:44f1:63e7:bfb8%4"));
-
+            con.Connect(Dns.GetHostEntry(Dns.GetHostName()).AddressList[1]);    //localhost
+            // con.Connect(IPAddress.Parse("fe80::c0a:44f1:63e7:bfb8%4"));
+            // con.Connect(IPAddress.Parse("127.0.0.1"));
 
             while (true)
             {