Search Unity

UNET equivalent of NetworkMessageInfo.timestamp

Discussion in 'UNet' started by gsus725, Jul 3, 2015.

  1. gsus725

    gsus725

    Joined:
    Aug 23, 2010
    Posts:
    250
    With the old networking NetworkMessageInfo.timestamp was used to determine how long a packet spent in transit and then you could do some prediction using that information.

    But how do I find how long a packet spent in transit using this new networking system?
     
  2. isidro02139

    isidro02139

    Joined:
    Jul 31, 2012
    Posts:
    72
    gsus725 I don't know the answer, but there is a community at irc.freenode.net in the channel #unity3d-unet that might have some answers!

    In addition some resources and code snippets are being gathered here:
    https://goo.gl/UmBBpM
     
  3. Necromantic

    Necromantic

    Joined:
    Feb 11, 2013
    Posts:
    116
  4. aabramychev

    aabramychev

    Unity Technologies

    Joined:
    Jul 17, 2012
    Posts:
    574
    You can use NetworkTransport.GetNetworkTimestamp() to get network timestamp and then you can send this timestamp to your peer. Peer can use GetRemoteDelayTimeMS() providing received timestamp as parameter. This function will return delay in ms. Unfortunately there was a bug in this function, it is fixed and will be available in the next patch
     
  5. Saishy

    Saishy

    Joined:
    Jun 3, 2010
    Posts:
    79
    It is not working again, returning 0 over long distance network on 5.6.2f1
     
  6. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    HLAPI or LLAPI?
     
  7. Saishy

    Saishy

    Joined:
    Jun 3, 2010
    Posts:
    79
    I think it's HLAPI
     
  8. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    I think that might be part of the issue. Works for me in LLAPI
     
  9. Saishy

    Saishy

    Joined:
    Jun 3, 2010
    Posts:
    79
    It does not work on clients.
     
  10. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    What do you mean? Basically, to use those methods. You need to get the LLAPI connectionId. And I don't think you can get that from HLAPI. Not sure though.
     
  11. Saishy

    Saishy

    Joined:
    Jun 3, 2010
    Posts:
    79
    You can.

    It not working on clients seems to be already a known bug.
     
    Deleted User likes this.
  12. Deleted User

    Deleted User

    Guest

    bump

    The current code would return zero
    Code (CSharp):
    1.  
    2. /*
    3. -------------------------------------------------------
    4.  Developer:  Alexander - twitter.com/wobes_1
    5.  Date:       11/08/2017 20:03
    6. -------------------------------------------------------
    7. */
    8.  
    9. using System;
    10. using System.Collections;
    11. using System.Collections.Generic;
    12. using UnityEngine;
    13. using UnityEngine.Networking;
    14.  
    15. public class CustomNetworkManager : NetworkManager
    16. {
    17.     public const short NetworkTimeMessageId = MsgType.Highest + 1;
    18.     public class NetworkTimeMessage : MessageBase
    19.     {
    20.         public float NetworkTime;
    21.         public int TimeStamp;
    22.     }
    23.  
    24.     private float networkTime;
    25.     private float timeReceived;
    26.  
    27.     public override void OnServerConnect(NetworkConnection conn)
    28.     {
    29.         base.OnServerConnect(conn);
    30.  
    31.         var msg = new NetworkTimeMessage();
    32.  
    33.         msg.NetworkTime = Time.time;
    34.         msg.TimeStamp = NetworkTransport.GetNetworkTimestamp();
    35.  
    36.         Debug.LogError(msg.TimeStamp);
    37.         Debug.LogError(msg.NetworkTime);
    38.  
    39.         conn.Send(NetworkTimeMessageId, msg);
    40.     }
    41.  
    42.     public override void OnClientConnect(NetworkConnection conn)
    43.     {
    44.         base.OnClientConnect(conn);
    45.  
    46.         client.RegisterHandler(NetworkTimeMessageId, OnClientNetworkTimeReceived);
    47.     }
    48.  
    49.     private void OnClientNetworkTimeReceived(NetworkMessage netMsg)
    50.     {
    51.         timeReceived = Time.time;
    52.         var msg = netMsg.ReadMessage<NetworkTimeMessage>();
    53.  
    54.         byte error;
    55.         float delay = NetworkTransport.GetRemoteDelayTimeMS(NetworkManager.singleton.client.connection.hostId, NetworkManager.singleton.client.connection.connectionId, msg.TimeStamp, out error);
    56.  
    57.         Debug.Log(delay);
    58.     }
    59. }
    60.  
     
  13. Deleted User

    Deleted User

    Guest

    It's not working if you trying to get stamp from the Server message on your client.
     
  14. Driiades

    Driiades

    Joined:
    Oct 27, 2015
    Posts:
    151
    It works only on server->client . The network timeStamp is available on server and GetRemoteDelay work on client.

    If you send NetworkTimeStamp from client to server it will not work, same for client to client. You need to synchronize server timeStamp to all clients and to send that synchronized value with your message.
     
    Deleted User likes this.
  15. Deleted User

    Deleted User

    Guest

    Actually it's not working server-> client, but it works client -> server, I mean you could get round trip of message from client on server side, but you cannot get it from server message on client side.
     
  16. Deleted User

    Deleted User

    Guest

    but thanks. I get that I should not synchronize the Time.time