Hi,
I am trying to make a game that uses a login system and also sends and receives data to and from PHP files on a server. Is there a way in which I can check whether the user is connected to the internet every few seconds?
I have tried using the Application.internetReachability property to check. But it doesn’t seem to work in the editor as well as the web player.
Any suggestions?
1 Answer
1
Application.internetReachability does not ensure actual connection to the internet, because like the documentation says:
“Note: Do not use this property to determine the actual connectivity. E.g. the device can be connected to a hot spot, but not have the actual route to the network.”
In general, TCP connections (e.g. using Sockets) cannot monitor the state of its connection without actually trying to use it. See the remarks on Socket.Poll on MSDN as well:
I realize this is unrelated to sockets, but the underlying issue is the same: If you want to test the health of a connection, the only way to be perfectly sure is to try to send some data and see if your remote host is reachable. When I faced this problem recently, I just sent some data to the remote host which I knew wouldn’t kill it or otherwise interfere locally. If you have access to those PHP files, maybe you can do something like that, too (a kind of ‘ping’ method).
I created a PHP file on my server and am checking/"pinging" it every X seconds. This seems to work for me.
– anniyan137