Search Unity

RegisterHandler() works in the editor, but not in a build

Discussion in 'Multiplayer' started by TFlippy, Aug 17, 2015.

  1. TFlippy

    TFlippy

    Joined:
    Nov 12, 2014
    Posts:
    27
    I'm trying to register handlers for custom network messages. It works flawlessly in the editor, but now when I'm doing the same on a build.

    When I'm trying to register a serverside handler as this, the NetworkManager HUD's host / server button doesn't execute anything past the RegisterHandler().

    Code (CSharp):
    1.  
    2. public class NetMessage
    3. {
    4.     public const short CHAT_MSG = MsgType.Highest + 1;
    5.     public const short PLAYER_INFO = MsgType.Highest + 2;
    6. }
    7.  
    8. public class Shared_NetHandler
    9. {
    10.     public static void Client_Register()
    11.     {
    12.         NetworkClient client = NetworkManagerEx.singleton.client;
    13.         client.RegisterHandler(NetMessage.CHAT_MSG, Chat_Shared.Singleton.Client_ReceiveChatMessage);
    14.         client.RegisterHandler(NetMessage.PLAYER_INFO, Shared_Steamworks.Singleton.Client_RequestSteamID);
    15.     }
    16.  
    17.     public static void Server_Register()
    18.     {
    19.         NetworkServer.RegisterHandler(NetMessage.CHAT_MSG, Chat_Shared.Singleton.Server_ReceiveChatMessage);
    20.         NetworkServer.RegisterHandler(NetMessage.PLAYER_INFO, NetworkManagerEx.AddPlayerInfo);
    21.     }
    22. }
    23.  
    Code (CSharp):
    1. public override void OnStartServer()
    2.     {
    3.         Chat_Client.Print("Started a server.");
    4.         Chat_Client.Print(string.Format("Registering serverside handlers, {0} registered.", NetworkServer.handlers.Count));
    5.         Shared_NetHandler.Server_Register();
    6.         Chat_Client.Print(string.Format("Done registering serverside handlers, {0} registered.", NetworkServer.handlers.Count));
    7.     }
    8.  
    9.     public override void OnClientConnect(NetworkConnection conn)
    10.     {
    11.         Chat_Client.Print(string.Format("Registering clientside handlers! C:{0}, S:{1}.", client.handlers.Count, NetworkServer.handlers.Count));
    12.         Shared_NetHandler.Client_Register();
    13.         Chat_Client.Print(string.Format("Done registering clientside handlers! C:{0}, S:{1}.", client.handlers.Count, NetworkServer.handlers.Count));
    14.  
    15.         ClientScene.Ready(conn);
    16.         Chat_Client.Print("Client is ready");
    17.         ClientScene.AddPlayer(0);
    18.  
    19.         Shared_NetHandler.Server_Register();
    20.         Chat_Client.Print(string.Format("Joined a server as client! C:{0}, S:{1}.", client.handlers.Count, NetworkServer.handlers.Count));
    21.     }
    When I tried logging it, it came up with this in the editor and build.

     
  2. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
    If you change the log level in the NetworkManager to "Debug" it will log message handler registration. Maybe that will give more info?
     
  3. TFlippy

    TFlippy

    Joined:
    Nov 12, 2014
    Posts:
    27
    ArgumentException: Value does not fall within the expected range.
    Here's the full log - pressed Start Host button and then closed myself.

    Shared_NetHandler.cs:51
    Code (CSharp):
    1. NetworkServer.RegisterHandler(NetMessage.CHAT_MSG, Chat_Shared.Singleton.Server_ReceiveChatMessage);
    NetworkManagerEx.cs:31
    Code (CSharp):
    1. Shared_NetHandler.Server_Register();

    Code (CSharp):
    1. Mono path[0] = 'C:/Unity 5/2D Cave Game/Build/2/test2_Data/Managed'
    2. Mono path[1] = 'C:/Unity 5/2D Cave Game/Build/2/test2_Data/Mono'
    3. Mono config path = 'C:/Unity 5/2D Cave Game/Build/2/test2_Data/Mono/etc'
    4. PlayerConnection initialized from C:/Unity 5/2D Cave Game/Build/2/test2_Data (debug = 0)
    5. PlayerConnection initialized network socket : 0.0.0.0 55320
    6. Multi-casting "[IP] 192.168.1.133 [Port] 55320 [Flags] 3 [Guid] 937473506 [EditorId] 636018801 [Version] 1048832 [Id] WindowsPlayer(Flippy) [Debug] 1" to [225.0.0.222:54997]...
    7. Waiting for connection from host on [192.168.1.133:55320]...
    8. PlayerConnection accepted from [192.168.190.1] handle:0x1c0
    9. Using monoOptions --debugger-agent=transport=dt_socket,embedding=1,defer=y,address=0.0.0.0:56506
    10. PlayerConnection already initialized - listening to [192.168.1.133:55320]
    11. Initialize engine version: 5.1.2p3 (65486b59c7a9)
    12. GfxDevice: creating device client; threaded=1
    13. Direct3D:
    14.     Version:  Direct3D 11.0 [level 11.0]
    15.     Renderer: NVIDIA GeForce GTX 760 (ID=0x1187)
    16.     Vendor:   NVIDIA
    17.     VRAM:     4027 MB
    18. Begin MonoManager ReloadAssembly
    19. Platform assembly: C:\Unity 5\2D Cave Game\Build\2\test2_Data\Managed\UnityEngine.dll (this message is harmless)
    20. Loading C:\Unity 5\2D Cave Game\Build\2\test2_Data\Managed\UnityEngine.dll into Unity Child Domain
    21. Platform assembly: C:\Unity 5\2D Cave Game\Build\2\test2_Data\Managed\Assembly-CSharp-firstpass.dll (this message is harmless)
    22. Loading C:\Unity 5\2D Cave Game\Build\2\test2_Data\Managed\Assembly-CSharp-firstpass.dll into Unity Child Domain
    23. Platform assembly: C:\Unity 5\2D Cave Game\Build\2\test2_Data\Managed\Assembly-CSharp.dll (this message is harmless)
    24. Loading C:\Unity 5\2D Cave Game\Build\2\test2_Data\Managed\Assembly-CSharp.dll into Unity Child Domain
    25. Platform assembly: C:\Unity 5\2D Cave Game\Build\2\test2_Data\Managed\UnityEngine.UI.dll (this message is harmless)
    26. Loading C:\Unity 5\2D Cave Game\Build\2\test2_Data\Managed\UnityEngine.UI.dll into Unity Child Domain
    27. Platform assembly: C:\Unity 5\2D Cave Game\Build\2\test2_Data\Managed\UnityEngine.Networking.dll (this message is harmless)
    28. Loading C:\Unity 5\2D Cave Game\Build\2\test2_Data\Managed\UnityEngine.Networking.dll into Unity Child Domain
    29. Platform assembly: C:\Unity 5\2D Cave Game\Build\2\test2_Data\Managed\UnityEngine.Analytics.dll (this message is harmless)
    30. Loading C:\Unity 5\2D Cave Game\Build\2\test2_Data\Managed\UnityEngine.Analytics.dll into Unity Child Domain
    31. Platform assembly: C:\Unity 5\2D Cave Game\Build\2\test2_Data\Managed\System.Core.dll (this message is harmless)
    32. - Completed reload, in  0.046 seconds
    33. desktop: 1920x1200 59Hz; virtual: 3840x1200 at -1920,0
    34. <RI> Initializing input.
    35.  
    36. <RI> Input initialized.
    37.  
    38. <RI> Initialized touch support.
    39.  
    40. Platform assembly: C:\Unity 5\2D Cave Game\Build\2\test2_Data\Managed\System.dll (this message is harmless)
    41. 0
    42. UnityEngine.Debug:Internal_Log(Int32, String, Object)
    43. UnityEngine.Debug:Log(Object)
    44. NetworkManagerEx:Start() (at C:\Unity 5\2D Cave Game\Assets\Resources\Experimental\NetworkManagerEx.cs:24)
    45. (Filename: C:/Unity 5/2D Cave Game/Assets/Resources/Experimental/NetworkManagerEx.cs Line: 24)
    46.  
    47. ArgumentException: Value does not fall within the expected range.
    48.   at Shared_NetHandler.Server_Register () [0x00000] in C:\Unity 5\2D Cave Game\Assets\Resources\Experimental\Shared_NetHandler.cs:51
    49.  
    50.   at NetworkManagerEx.OnStartServer () [0x00028] in C:\Unity 5\2D Cave Game\Assets\Resources\Experimental\NetworkManagerEx.cs:31
    51.  
    52.   at UnityEngine.Networking.NetworkManager.StartServer (UnityEngine.Networking.Match.MatchInfo info, UnityEngine.Networking.ConnectionConfig config, Int32 maxConnections) [0x00000] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkManager.cs:218
    53.  
    54.   at UnityEngine.Networking.NetworkManager.StartServer (UnityEngine.Networking.Match.MatchInfo info) [0x00000] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkManager.cs:213
    55.  
    56.   at UnityEngine.Networking.NetworkManager.StartServer () [0x00000] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkManager.cs:208
    57.  
    58.   at UnityEngine.Networking.NetworkManager.StartHost () [0x00006] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkManager.cs:393
    59.  
    60.   at UnityEngine.Networking.NetworkManagerHUD.OnGUI () [0x00075] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkManagerHUD.cs:67
    61. (Filename: C:/Unity 5/2D Cave Game/Assets/Resources/Experimental/Shared_NetHandler.cs Line: 51)
    62.  
    63. Waiting for finish
    64.  
     
    Last edited: Aug 17, 2015
  4. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
    ok, there is an exception registering your message handler. Is the Chat_Shared.Singleton initialized at the time?
     
  5. TFlippy

    TFlippy

    Joined:
    Nov 12, 2014
    Posts:
    27
    Oh, it's not. Turns out that I called it too early before the GameObjects were actually created.