Search Unity

connectionToServer.hostId == -1 in host mode

Discussion in 'Multiplayer' started by phaem, Sep 26, 2017.

  1. phaem

    phaem

    Joined:
    Jan 5, 2015
    Posts:
    76
    Hello Unity community!

    I've created a simple prototype where box is moving when user press arrows.
    Every 0.1 seconds server sends a message to the client.
    On the client side all I want is just print the message delay.
    For this purpose I'm using NetworkTransport.GetNetworkTimestamp on the server and NetworkTransport.GetRemoteDelayTimeMS on the client side.
    When I start the game as a host in editor using "LAN Host" button, the connectionToServer.hostId property returns -1 instead of valid hostId.
    This results in the following error:

    Here is my code for retrieving the delay in seconds.

    Code (CSharp):
    1.     private float GetRemoteDelay(Sync sync)
    2.     {
    3.         var error = default(byte);
    4.         var delay = NetworkTransport.GetRemoteDelayTimeMS(connectionToServer.hostId,
    5.             connectionToServer.connectionId,
    6.             sync.serverTimestamp,
    7.             out error);
    8.  
    9.         if(error != 0)
    10.         {
    11.             Debug.Log("Error:" + error);
    12.         }
    13.  
    14.         return delay / 1000f;
    15.     }
    I've checked NetworkMessage.conn.hostId in the message handler, it's -1 too.
    Checked NetworkManager.singleton.client.connection.hostId, it's -1.
    What am I doing wrong? How to avoid that? Where to take hostId and connectionId when runnig a host?

    Thank you!
     
    Last edited: Sep 28, 2017