I’m checking for online connectivity using Application.internetReachability against both LAN and Data Networks. Unfortunately I’ve found that if the client is connected to a network, but that network is not connected to the internet, the program still assumes the client is connected.
I’ve tried countering this by running a ping test, but the ping periodically returns false positives, saying the ping was successful after x time even when the computer or device is entirely disconnected.
Exploring further, while disconnected from the internet I pinged an ip from command prompt, which produced the following results:
Request timed out.
Reply from 192.168.0.123: Destination host unreachable.
Reply from 192.168.0.123: Destination host unreachable.
Reply from 192.168.0.123: Destination host unreachable.
The Unity Ping class seemingly cannot differentiate between an “unreachable” reply, and a positive reply. Is there an alternative means of checking for connectivity?
(Adding a comment to an old posting in case somebody finds this using search…)
To truly know internet can be reached, there needs to be “captive portal detection”. It’s a technique also used by operating systems, where you simply do a request to an url which gives a reply with known contents. That helps to know if you’re e.g. hitting a public WiFi login page. Just checking Application.internetReachability or doing a Ping doesn’t guarantee that internet connection works.
I have made an easy asset called Internet Reachability Verifier and it allows you to use one of the captive portal detection methods maintained by big OS vendors, or your own custom url. It keeps you up-to-date whether you have verified internet access and it works with desktop and mobile platforms (self-hosted custom method can be used with the web player plugin if you think that’s necessary).
If you want to give it a try, there’s more info here: Internet Reachability Verifier by Strobotnik (for Unity®)
Are you just watching for Ping.isDone()? If a ping times out internally it will still register as finished for isDone(). You need to check Ping.time. If the ping timed out it’s time should still be listed as -1, whereas if it was successful it will show how long it took before success.