- Home /
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. :)
Answer by Andrey-Postelzhuk · Jul 28, 2014 at 01:46 PM
Wow! You can't do this in one function. Try to read about coroutines first: http://docs.unity3d.com/Manual/Coroutines.html
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.
I fixed link. Read about yield statement and coroutines in Unity3D.
Your answer
Follow this Question
Related Questions
Yield Wait for Seconds (A little help here) 2 Answers
Only the first half of my coroutine works 1 Answer
Wait For Seconds c# 3 Answers
WaitForSeconds not running 2 Answers
Why Won't My Coroutine Yield? 2 Answers