RTT (Round Trip Time) always return Zero in Unity DOTs Project

318 Views Asked by At

I'm trying to use the DOTsSample Unity project and want to use this NetworkStatistics Class (https://github.com/Unity-Technologies/DOTSSample/blob/master/Assets/Scripts/Game/Main/NetworkStatisticsClient.cs) and trying to write a script to show the network statistics in my game, but the thing is it always returns 0.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NetStats : MonoBehaviour
{
    // Start is called before the first frame update


    NetworkStatisticsClient networkStatisticsClient;
    private SocketTransport m_Transport;
    private NetworkClient m_NetworkClient;

    void Start()
    {

        m_Transport = new SocketTransport();
        m_Transport.Connect("127.0.0.1",80);

        m_NetworkClient = new NetworkClient(m_Transport);

        if (Application.isEditor || Game.game.buildId == "AutoBuild")
            NetworkClient.clientVerifyProtocol.Value = "0";

        m_NetworkClient.UpdateClientConfig();
        networkStatisticsClient = new NetworkStatisticsClient(m_NetworkClient);


    }

    // Update is called once per frame
    void Update()
    {
        //Client isConnected is False thus, the connection is not establishment is not correct
        Debug.Log("Rtt: " +  m_NetworkClient.isConnected + networkStatisticsClient.rtt.average);
    }
}

Can anybody please help me with this?

1

There are 1 best solutions below

4
Athanasios Kataras On

As per documentation, I would expect you to connect to a server somewhere in the start function.

https://docs.unity3d.com/2017.3/Documentation/ScriptReference/Networking.NetworkClient.Connect.html

    public void Start()
    {
        myClient = NetworkClient.Instance;

        myClient.RegisterHandler(MsgType.SYSTEM_CONNECT, OnConnected);
        myClient.RegisterHandler(MsgType.SYSTEM_DISCONNECT, OnDisconnected);
        myClient.RegisterHandler(MsgType.SYSTEM_ERROR, OnError);
        // this line here is important
        myClient.Connect("127.0.0.1", 8888);
    }

The network client is used to make rpc calls to a server. It's not a generic client medically abstracting all network connectivity.