Search Unity

What is causing this console output to be seperated?

Discussion in 'Connected Games' started by ggssti, Feb 11, 2019.

  1. ggssti

    ggssti

    Joined:
    Sep 7, 2018
    Posts:
    2
    Code:

    Code (CSharp):
    1. public static void StartReceivingData()
    2.     {
    3.         try
    4.         {
    5.             SocketAsyncEventArgs saea = SocketAsyncEventArgsPool.Pop();
    6.             saea.SetBuffer(new byte[1024], 0, 1024);
    7.             saea.RemoteEndPoint = new IPEndPoint(IPAddress.Any, 0);
    8.  
    9.             if (!serverSocket.IsBound)
    10.             {
    11.                 serverSocket.Bind(serverIPEP);
    12.             }
    13.  
    14.             saea.Completed += ReceiveCompleteCallback;
    15.  
    16.             if (!serverSocket.ReceiveFromAsync(saea))
    17.             {
    18.                 Debug.Log("Failed to receive data");
    19.  
    20.                 if (retryCount++ >= 10)
    21.                 {
    22.                     return;
    23.                 }
    24.                 else
    25.                 {
    26.                     StartReceivingData();
    27.                 }
    28.             }
    29.         }
    30.         catch (Exception excp)
    31.         {
    32.             Debug.Log(excp.ToString());
    33.             return;
    34.         }
    35.     }
    36.  
    37.     private static void ReceiveCompleteCallback(object sender, SocketAsyncEventArgs e)
    38.     {
    39.         if (!ConnectionExists(e.RemoteEndPoint)) { if (AddNewConnection(e.RemoteEndPoint)) { ProcessPacket(e.Buffer); } }
    40.         else { ProcessPacket(e.Buffer); }
    41.         StartReceivingData();
    42.     }
    43.  
    44. private static void ProcessPacket(byte[] buffer)
    45.     {
    46.         Packet packet = new Packet(buffer);
    47.  
    48.         switch (packet.Type)
    49.         {
    50.             case PacketType.REQJ:
    51.                 ProcessJoinRequest(buffer);
    52.                 break;
    53.         }
    54.     }
    55.  
    56.     private static void ProcessJoinRequest(byte[] buffer)
    57.     {
    58.         RequestJoinPacket REQJ = new RequestJoinPacket(buffer);
    59.         string payload = Encoding.ASCII.GetString(REQJ.Payload);
    60.         Debug.Log(payload);
    61.  
    62.         ApproveJoinPacket APPJ = new ApproveJoinPacket();
    63.         SocketAsyncEventArgs saea = new SocketAsyncEventArgs();
    64.         saea.SetBuffer(APPJ.GetBytes(), 0, APPJ.GetBytes().Length);
    65.         saea.RemoteEndPoint = connections[0].endPoint;
    66.  
    67.         saea.Completed += CompletedCallback;
    68.  
    69.         serverSocket.SendAsync(saea);
    70.     }
    This code outputs the messages found in the attached picture.

    Why is the first string I receive grouped separate from the rest of the strings?
     
  2. ggssti

    ggssti

    Joined:
    Sep 7, 2018
    Posts:
    2
    Had to reupload image.

    The "sent message to" is from a different script.
     

    Attached Files: