Search Unity

Unknown Message id sometimes interrupt the network connection?

Discussion in 'Multiplayer' started by Babbyo, Jul 25, 2017.

  1. Babbyo

    Babbyo

    Joined:
    Apr 27, 2017
    Posts:
    5
    Hi,
    I am working on a project for data communication between hololens and PC. The hololens as client, sending camera pose and virtual objects pose, PC as server receiving the data and sending back with adding updates. The connection I create is based on low level scripting with using Networkclient and Networkserver class. It works fine for most of the time, But sometimes the connection will be interrupted by the Unknown Message id with a large number, I am confused about this. I code specific connection id in the beginning and have no idea about this id come from. Does anyone know about my problem?
    Thanks!
    structure:
    hololens--client
    Sending : camera pose, virtual contents pose (to same port, but with different ids )
    Receiving. update virtual contents pose

    PC --server
    Sending: update virtual contents pose(with another id )
    Receiving: camera pose, virtual contents pose
     
  2. robochase

    robochase

    Joined:
    Mar 1, 2014
    Posts:
    244
    what's the message id? any other errors?

    are you using the relay server? back when i was using the relay server, the connection would abruptly terminate in a weird way if i was using too much bandwidth.
     
  3. Babbyo

    Babbyo

    Joined:
    Apr 27, 2017
    Posts:
    5
    Hi, Soooorry for my late response! I am not sure I am using relay server or not. Here the follow is my partial code for describing the problem.

    Client:
    Code (CSharp):
    1.  
    2. // initialization
    3. public static NetworkClient client;
    4. public string Serverip = "192.168.1.100";
    5. public int Serverport = 2345;
    6.  
    7. //Message type
    8. public class MyMsgType
    9.     {
    10.         public static short Camerapose = MsgType.Highest + 100;
    11.         public static short Cubepose = MsgType.Highest + 200;
    12.         public static short backpose = MsgType.Highest + 300;
    13.     };
    14.  
    15. // Message base
    16. public class Positionmsg : MessageBase
    17.     {
    18.         public Matrix4x4 transformmatrix;
    19.         public double deltatime;
    20.         public bool flag;
    21.         public int timeindex;
    22.     }
    23.  
    24.     public class Cameramsg : MessageBase
    25.     {
    26.         public Vector3 cameraP;
    27.         public Quaternion cameraQ;
    28.     }
    29.  
    30.     public class Estimatormsg : MessageBase
    31.     {
    32.         public Vector3 position;
    33.         public Quaternion rotation;
    34.         public int timeindex_back;
    35.     }
    36.  
    37.  
    38. // Setup client function
    39. void Setupclient()
    40.     {
    41.         client = new NetworkClient();
    42.         client.RegisterHandler(MsgType.Connect, OnConnected);
    43.         client.RegisterHandler(MyMsgType.backpose, Onreceiving);  // receiving the message from Server
    44.         client.RegisterHandler(MsgType.Error, OnError);
    45.         client.Connect(Serverip, Serverport);
    46.     }
    47.  
    48. void OnConnected(NetworkMessage netMsg)
    49.     {
    50.         Debug.Log("Connected to server");
    51.         isAtstartup = false;
    52.     }
    53. void Onreceiving(NetworkMessage netmsg)
    54.     {
    55.         Estimatormsg Message = netmsg.ReadMessage<Estimatormsg>();
    56.         p = Message.position;
    57.         Q = Message.rotation;
    58.  
    59.     }
    60.  
    61.     void OnError(NetworkMessage netMsg)
    62.     {
    63.         var errorMsg = netMsg.ReadMessage<ErrorMessage>();
    64.         Debug.Log("Error:" + errorMsg.errorCode);
    65.     }
    66.  
    67.  
    68. // two sending functions,  call in the update function under the different objects.
    69. public static void Sending(Matrix4x4 result, double delta, int time_index)
    70.     {
    71.         Positionmsg msg = new Positionmsg();
    72.         msg.transformmatrix = result;
    73.         msg.deltatime = delta;
    74.         msg.flag = true;
    75.         msg.timeindex = time_index;
    76.         client.Send(MyMsgType.Cubepose, msg);
    77.         //TimeDetectdone = DateTime.Now;
    78.     }
    79.  
    80.     public static void CameraSending(Vector3 p, Quaternion q)
    81.     {
    82.         Cameramsg msg = new Cameramsg();
    83.         msg.cameraP = p;
    84.         msg.cameraQ = q;
    85.         client.Send(MyMsgType.Camerapose, msg);
    86.     }

    Server:
    Code (CSharp):
    1. // Same initialization as the client
    2. private int Serverport = 2345;
    3. // message type
    4. public class MyMsgType
    5.     {
    6.         public static short Camerapose = MsgType.Highest + 100;
    7.         public static short Cubepose = MsgType.Highest + 200;
    8.         public static short backpose = MsgType.Highest + 300;
    9.     };
    10.  
    11. //message base
    12.     public class Positionmsg : MessageBase
    13.     {
    14.         public Matrix4x4 transformmatrix;
    15.         public double deltatime;
    16.         public bool flag;
    17.         public int timeindex;
    18.     }
    19.  
    20.     public class Cameramsg : MessageBase
    21.     {
    22.         public Vector3 cameraP;
    23.         public Quaternion cameraQ;
    24.     }
    25.  
    26.     public class Estimatormsg : MessageBase
    27.     {
    28.         public Vector3 position;
    29.         public Quaternion rotation;
    30.         public int timeindex_back;
    31.     }
    32.  
    33. //set up server
    34. void SetupServer()
    35.     {
    36.         NetworkServer.Reset();
    37.         if (NetworkServer.Listen(Serverport))
    38.             {
    39.                 NetworkServer.RegisterHandler(MyMsgType.Camerapose, OnreceivingCamera);
    40.                 NetworkServer.RegisterHandler(MyMsgType.Cubepose, Onreceiving);
    41.         }
    42.     }
    43.  
    44. //two receiving function
    45. void Onreceiving(NetworkMessage netmsg)
    46.     {
    47.         Positionmsg Message = netmsg.ReadMessage<Positionmsg>();
    48.         Transmatrix = Message.transformmatrix;
    49.         deltaTime = Message.deltatime;
    50.         msgback.position = transform.position;
    51.         msgback.rotation = transform.rotation;
    52.         msgback.timeindex_back = Message.timeindex;
    53.         //Server sending back message to client    
    54.         NetworkServer.SendToAll(MyMsgType.backpose,msgback);
    55.         Markerfind = false;
    56.     }
    57.  
    58.  
    59.     void OnreceivingCamera(NetworkMessage netmsg)
    60.     {
    61.         Cameramsg Message = netmsg.ReadMessage<Cameramsg>();
    62.         receiveP = Message.cameraP;
    63.         receiveQ = Message.cameraQ;
    64.         Camera.main.transform.position = receiveP;
    65.         Camera.main.transform.rotation = receiveQ;
    66.     }
    Then when I start running the program, In the PC part will sometime be interrupt by this message.
    " Unknow message id 65536, ....." and the number of id is not identical, but all of them are large and unknown number, such like that. I could click the 'pause ' button to continue running and later it maybe will stop again, seems like random, not fixed.
     
    Last edited: Aug 3, 2017