Search Unity

Get Latency and Ping players

Discussion in 'Multiplayer' started by Dark-Protocol, Jul 29, 2015.

  1. Dark-Protocol

    Dark-Protocol

    Joined:
    Nov 19, 2011
    Posts:
    279
    Hi guys, I'm having a little bit of a struggle moving over to UNET from the legacy networking solution here :)

    In the legacy Unity networking I was able to tell the latency in seconds of each RPC call using the NetworkMessageInfo argument that was passed to the method but it seems that this is gone in UNET. What is the equivalent to this when using ClientRPC and Command? I need this information for compensation purposes.

    Also how can I ping other players ? In the NetworkConnection class there are GetStatsIn and GetStatsOut but they don't hold information about pings. There is also lastMessageTime but this is still not quite what I need. What is the substitute for Network.GetAveragePing in UNET ?
     
  2. l3fty

    l3fty

    Joined:
    Mar 23, 2013
    Posts:
    87
    bartm4n likes this.
  3. Dreamteck

    Dreamteck

    Joined:
    Feb 12, 2015
    Posts:
    336
    Hi Dark, did you ever resolve the issue with the message timestamp/latency ? I need to know the time between sending and receiving a NetworkMessage. In the old networking system we had Network.time and messages had NetworkMessageInfo which stored information about when the message was sent. Based on that we could calculate the trip time. But in UNET there is no synchronized network time and therefore we can't even make this functionality by ourselves.
     
  4. Dark-Protocol

    Dark-Protocol

    Joined:
    Nov 19, 2011
    Posts:
    279
    Unfortunately I did not find any way other than just establishing an additional legacy network connection and getting Network.time from there. Which is an awful solution and I encourage you to not do that. I hope they add synchronized time and message timestamps in the future as my game depends on that.
     
  5. Hope I'm not wasting your time, but maybe this could help a bit?
     
    Zenov likes this.
  6. Dark-Protocol

    Dark-Protocol

    Joined:
    Nov 19, 2011
    Posts:
    279
    Thanks for the link Enrico! I've seen all of these videos but unfortunately they didn't help. I need to know the exact time a message took to travel from sending to receiving. This would include the traveling time and the time spent in the buffer.
    The legacy networking system took care of this pretty easily but just having a synchronized time between machines. Then upon receiving you can just compare the send timestamp of the message with the current time. Unfortunately I can't seem to find a synchronized time variable in UNET.
     
  7. I've also found this in the release notes for the latest version
    Networking: Timing service is working now
    Don't really know what this is but maybe it means something

    Have you also looked in the NetworkConnection class? There are things like lastMessageTime and some statistics things.
     
    Last edited by a moderator: Sep 2, 2015
  8. Dark-Protocol

    Dark-Protocol

    Joined:
    Nov 19, 2011
    Posts:
    279
    Hmm, timing service doesn't ring a bell here either.
    lastMessageTime is supposed to return the last time a message has been received on the connection.
    I found this: http://docs.unity3d.com/ScriptReference/Networking.NetworkTransport.GetNetworkTimestamp.html and I think it might be what I'm after but since I'm using a network manager and I'm not initializing the NetworkTransport, I don't know if it's going to work. And also I don't know if this is synchronized between all the peers.
     
    Last edited: Sep 5, 2015
  9. chrismarch

    chrismarch

    Joined:
    Jul 24, 2013
    Posts:
    472
    NetworkTransport.GetCurrentRtt seems accurate on the server in 5.1.1f1 Windows.
     
  10. sglindme

    sglindme

    Joined:
    Jun 30, 2015
    Posts:
    18
    How do I use GetCurrentRTT? How do I find the host ID and my connectionID to use as parameters for the function?
     
  11. chrismarch

    chrismarch

    Joined:
    Jul 24, 2013
    Posts:
    472
    Code (CSharp):
    1. for (int i = 0; i < NetworkServer.connections.Count; ++i) {
    2.     NetworkConnection c = NetworkServer.connections[i];
    3.    if (c == null) {
    4.       continue;
    5.    }
    6.    byte error;
    7.    int rtt = NetworkTransport.GetCurrentRtt(c.hostId, c.connectionId, out error);
    8. }
     
    Jordii likes this.
  12. Dreamteck

    Dreamteck

    Joined:
    Feb 12, 2015
    Posts:
    336
    I tested NetworkTransport.timestamp and it doesn't seem to be synchronized between peers. That's really bad. It says in the docs that it could be used to find message latency but I don't think that's possible after all. The only method I can come up with so far for having a synchronized timer would be ping-pong messages but there's gotta be a better way!
     
  13. emrys90

    emrys90

    Joined:
    Oct 14, 2013
    Posts:
    755
    Was this changed? NetworkTransport.GetCurrentRtt returns 0 for me on 5.3.
     
  14. chrismarch

    chrismarch

    Joined:
    Jul 24, 2013
    Posts:
    472
    It works for us on our servers. Are you testing on a server or a client?
     
  15. Whippets

    Whippets

    Joined:
    Feb 28, 2013
    Posts:
    1,775
    Testing on a client in 5.3.2 - NetworkTransport.GetCurrenRtt returns 0 for me as well.
     
  16. Anisoropos

    Anisoropos

    Joined:
    Jul 30, 2012
    Posts:
    102
  17. rocketkittens

    rocketkittens

    Joined:
    Dec 17, 2016
    Posts:
    1
    Code (CSharp):
    1. public class MyClass: NetworkBehaviour {
    2.     private NetworkClient client;
    3.     void Start() {
    4.         client = GameObject.Find("NetworkManager").GetComponent<NetworkManager>().client;
    5.     }
    6.     void Update() {
    7.         Debug.Log(client.GetRTT());
    8.     }
    9. }
     
  18. kfarris

    kfarris

    Joined:
    May 21, 2013
    Posts:
    16

    Hello, i was wondering if this is still usable?