I’m trying to check connectivity from one machine to another. I tried Unity’s Ping but that is simply not useable as it just shows whether we got any response and the time it took. For example if my router gives a “destination net unreachable” Unity Ping interprets that too as a response and shows a response time even though we didn’t really get a response from the address we were pinging.
So I’m thinking about using the .net Ping classes but there I’ve run into a problem with running it asynchronously. I’m not really familiar with c# async functions. Can they be easily run inside Unity coroutines?
I tried this:
IEnumerator BetterPing() {
System.Net.NetworkInformation.Ping pinger = new System.Net.NetworkInformation.Ping();
Task<PingReply> pingTask = pinger.SendPingAsync(loader.config["serverAddress"]);
yield return new WaitUntil(() => pingTask.IsCompleted);
UnityEngine.Debug.Log(pingTask.Result.Status.ToString());
}
But that just hangs the entier app and doesn’t continue to the next frame until the ping task has completed. Is there a better way to do this? Or a better method to check connectivity to another machine (and I don’t mean to a server, internet or website etc, I mean simply from a pc to a pc)?