Easy, you don't have a try/catch block around your method.
I didn't find the overload constructor for Ping(string), but I assume it's the same as creating a Ping class then doing Send(string) (i.e. it immediately attempts to ping the address provided in the string).
If you check the documentation for [Ping.Send(string)][1] it throws various exceptions you have to deal with (otherwise your program will crash).
Best guess is it's throwing the PingException since it can't resolve the address. Catch the exception, then do something that makes sense for your application (warn user can't ping or what have you).
IEnumerator CheckConnectionToMasterServer() {
try{
Ping pingMasterServer = new Ping("74.125.224.72");
float startTime = Time.time;
while (!pingMasterServer.isDone && Time.time < startTime + 5.0f) {
yield return new WaitForSeconds(5.0f);
}
if(pingMasterServer.isDone && pingMasterServer.time > 2) {
Debug.Log ("IntenetON" );
} if(pingMasterServer.isDone && pingMasterServer.time<=1) {
Debug.Log ("IntenetOFF" );
}
}
catch (exception e)
{
Debug.LogWarning("Couldn't ping: " + e.message);
}
}
[1]: https://msdn.microsoft.com/en-us/library/7hzczzed(v=vs.110).aspx
↧