C# How to ping servers and get server latency?

Hi, I was trying to make a mutiplayer menu with all the online servers and stuff, I was wondering how could i make the server latency. I’ve tried this.

IEnumerator PingServer(string ip){
	Ping ping = new Ping(ip);
	while(!ping.isDone){
    yield return 0;
	}
	yield return ping.time;
}

void OnGUI() {
     GUI.Box(new Rect( 0,0,100,20),StartCoroutine(PingServer(PhotonNetwork.PhotonServerSettings.ServerAddress)) + " ms");
}

But the return value is UnityEditor.Coroutine so I’m not sure whats wrong. Please help, Thanks in advance. :slight_smile:

Wow! You can’t do this in one function. Try to read about coroutines first:

You can’t return from coroutine function something else.

Pinging a server should be an async operation. Make Ping variable a class member and check it’s flag isDone every frame.