Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Unity Multiplayer "Unknown message ID" error

Discussion in 'Multiplayer' started by SiewYoong_V3, Aug 14, 2018.

  1. SiewYoong_V3

    SiewYoong_V3

    Joined:
    Apr 4, 2018
    Posts:
    2
    Hi, I have been using Unity for awhile, but am very new to UNet. I'm also using version 2017.3.0f3.

    I'm trying to send network messages via NetClient.Send, but couldn't get it to work after a whole day of testing and researching.

    My test environment is, the editor being the host, and a build being the client.

    When I tried sending message from client to host, i will get the following error from the host
    Unknown message ID 147 connId:1


    And when I tried sending message from host to client, i will get the following error from the host
    Local invoke: Failed to find local connection to invoke handler on [connectionId=0] for MsgId:147


    At first I thought the handler wasn't registered properly, but when I tested on both host and client, it seems to exist on both side
    Is msg type registered: True


    I tried searching around the net, but couldn't find any solution. I have even check the Networking source code, it seems like at line 459, [msgDelegate] wasn't able to find the handler.

    Hoping someone here can help me figure out what went wrong with my implementation.
    Below is the code that I use for testing sending network messages.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Networking;
    3. using UnityEngine.Networking.NetworkSystem;
    4.  
    5. public class NetTest : NetworkBehaviour
    6. {
    7.     private NetworkManager netManager;
    8.     private NetworkClient netClient;
    9.  
    10.     public class MyMsgType
    11.     {
    12.         public static short Test = MsgType.Highest + 100;
    13.     }
    14.  
    15.     // Use this for initialization
    16.     void Start () {
    17.         netManager = NetworkManager.singleton;
    18.         netClient = netManager.client;
    19.         netClient.RegisterHandler(MyMsgType.Test, OnNetworkInfo);
    20.         Debug.LogError("Is msg type registered: " + netClient.connection.CheckHandler(MyMsgType.Test));
    21.     }
    22.    
    23.     // Update is called once per frame
    24.     void Update () {
    25.         if(Input.GetKeyUp(KeyCode.Space))
    26.         {
    27.             StringMessage message = new StringMessage();
    28.             message.value = "hello from the other side~";
    29.             netClient.Send(MyMsgType.Test, message);
    30.         }
    31.     }
    32.  
    33.     void OnNetworkInfo(NetworkMessage netMsg)
    34.     {
    35.         Debug.LogError("received: " + netMsg.ReadMessage<StringMessage>().value);
    36.     }
    37. }