Search Unity

GetRemoteDelayTimeMS - Weird Results

Discussion in 'Multiplayer' started by ReiAyanami, Jun 12, 2015.

  1. ReiAyanami

    ReiAyanami

    Joined:
    Aug 6, 2010
    Posts:
    53
    Hey,

    I am currently adapting my game to use the new low level Network API, but I noticed a little problem regarding the GetRemoteDelayTimeMS function.

    I am sending the timestamp to a connected client, receive it there and then I am trying to use this timestamp to find out the message delivery time with the above mentioned function - like I would've used NetworkMessageInfo's timestamp to find the delay in RakNet.

    NetworkTransport.GetRemoteDelayTimeMS(client.HostID, client.ConnectionID, timestamp, out error);

    The "client" object is a class containing the on connect event received hostID and connectionID, timestamp is received from the message. However, this results in really high numbers like 2971368 - in local testing, where I assume it should be close to zero. The timestamp is definitely the same as send from the server.

    Am I misunderstanding this function? If so, how would I get the delay from Sending->Receiving?
    (I want to find the clock offset by sending the server utc time, adding the message delay and then subtracting the client utc time, so I can later use TimeDate to define match start times/end times and more.)
     
  2. AlwaysBeCoding247

    AlwaysBeCoding247

    Joined:
    Jan 27, 2014
    Posts:
    41
    @ReiAyanami I had maybe the same problem. Here is a snippet of how I am doing it in a test for testing client latency when firing a weapon to then do hitbox rewinding on server..

    When client fires weapon, send client time..

    Code (CSharp):
    1. MyMessages.FireWeaponMessage shot = new MyMessages.FireWeaponMessage();
    2. shot.timeStamp = NetworkTransport.GetNetworkTimestamp(); // timeStamp is an int in message class
    3. NetworkManager.singleton.client.Send((short) MyMessages.MyMessageTypes.FIRE_SHOT, shot);

    In the server handler for fire weapon messages calculate this clients shot latency.. unpack the clients time and pass it to the GetRemoteDelayTimeMS() on server

    Code (CSharp):
    1. private void OnServerShotMessage(NetworkMessage netMsg)
    2.     {
    3.         MyMessages.FireWeaponMessage msg = netMsg.ReadMessage<MyMessages.FireWeaponMessage>();
    4.         byte error;
    5.         int delay = NetworkTransport.GetRemoteDelayTimeMS(netMsg.conn.hostId, netMsg.conn.connectionId, msg.timeStamp, out error);
    6.         Debug.Log("Remote latency from client: " + delay + "ms");
    7.     }
    This is logging seemingly accurate latency times. Local client/host logs "0ms".. "remote"(on same machine) is logging between "5ms" to "30ms" while bullets are flying. I'm going to hook it up with the network simulator then to make sure everything is actually accurate then. I could be do something wrong. I just threw it together
     
    Last edited: Jun 12, 2015
  3. ReiAyanami

    ReiAyanami

    Joined:
    Aug 6, 2010
    Posts:
    53
    Thanks for the message!

    It's exactly the way I am doing it, except that I am using the low level API so I don't use the NetworkMessage :) Mine still fails with really weird delay times.


    I also encountered a new problem, I have a setup message that I send to the server when the client successfully connected. When I use the ReliableSequenced channel type, it only works once - disconnecting and then reconnecting will send the message, but the server never receives it. Just using the Reliable channel type always works. It's not a problem for this specific message, but I wonder what that would do the message where I rely on the order (other setup stuff, that requires other things to be setup before).
    Any ideas about that, anyone?
     
  4. aabramychev

    aabramychev

    Unity Technologies

    Joined:
    Jul 17, 2012
    Posts:
    574
    Hi Rei
    It was long time ago when I did implement that probably something has been broken. So, report the bug please about timestamp (and attach your project please as i will need to check other digits).

    Other problem (about ReliableSequenced ) is definitely bug and it has been already fixed and will be in patch 1.

    sorry for bugs :(
    Alex
     
    AlwaysBeCoding247 likes this.
  5. zuzzu

    zuzzu

    Joined:
    Feb 2, 2013
    Posts:
    404
    I have exactly the same problem in Unity 5.1. GetRemoteDelayTimeMS reports delays close to ~1200 ms between app instances on my local machine.

    @ReiAyanami If you've filled a bug request, can you post a link to it?
     
  6. ReiAyanami

    ReiAyanami

    Joined:
    Aug 6, 2010
    Posts:
    53
    @aabramychev
    @zuzzu

    Just did! Case number is 704521 and here is a link to the bugtracker: http://fogbugz.unity3d.com/default.asp?704521_sa7jrocrgrd5hpko

    Noticed something else while creating the minimal example (changed the low level example slightly for that) - it only appears on the client, and the received delay time slowly approaches a normal value after a while. (Which is still a problem for my case, as I only need the delay once at the beginning)

    As far as I can see the bug tracker does not openly display my code, so in case you want to check the code, here it is: http://pastebin.com/0FeCXpBT
     
  7. Ghosthowl

    Ghosthowl

    Joined:
    Feb 2, 2014
    Posts:
    228
    I just ran into this issue as well, will wait for Alex. Thanks for bringing this up!
     
  8. powdered_swords

    powdered_swords

    Joined:
    Mar 11, 2013
    Posts:
    28
    I just noticed I was still encountering this same problem even after updating to 5.1.1p2. Can anyone else confirm whether this has been fixed in the latest version.
     
  9. aabramychev

    aabramychev

    Unity Technologies

    Joined:
    Jul 17, 2012
    Posts:
    574
    Not fixed yet. I will inform when it will be fixed
     
  10. rob_vld

    rob_vld

    Joined:
    Jul 9, 2013
    Posts:
    191
    is NetworkTransport.GetCurrentRtt also not working? - is there currently any way on getting an accurate h/rtt ?
     
    Last edited: Jul 16, 2015
  11. aabramychev

    aabramychev

    Unity Technologies

    Joined:
    Jul 17, 2012
    Posts:
    574
    ok, timing service has been fixed and will be available in 5.1.2 patch 1.
    rtt measurement and other low level statistic function have been fixed as well and most probably will be available in 5.1.2 patch 1 (or less probably patch 2)
     
    Last edited: Jul 16, 2015
  12. aabramychev

    aabramychev

    Unity Technologies

    Joined:
    Jul 17, 2012
    Posts:
    574
    note that rtt exposed is measured by 8 last probes, each probe came from ping, so it is average value from last 8 ping timeout periods
     
  13. rob_vld

    rob_vld

    Joined:
    Jul 9, 2013
    Posts:
    191
    woohooo!
     
  14. rob_vld

    rob_vld

    Joined:
    Jul 9, 2013
    Posts:
    191
    *awaits patch 2* :(
     
  15. TrungDung

    TrungDung

    Joined:
    Sep 16, 2015
    Posts:
    1
    NetworkTransport.GetCurrentRtt() always return 0 in 5.1.2 patch 3. Do I miss any thing? Any one help me
     
  16. emrys90

    emrys90

    Joined:
    Oct 14, 2013
    Posts:
    755
    Any news on this? I am on 5.3 and NetworkTransport.GetCurrentRtt returns 0 for remote player on local machine.
     
  17. buronix

    buronix

    Joined:
    Dec 11, 2013
    Posts:
    111
    Bump NetworkTransport.GetCurrentRtt keeps returning 0.