- Home /
How many times do I need to check for internet?
Does require persistent WiFi do anything other than allow your app to use networking features? I currently have code like checks for internet:
public void CheckInternetConnection()
{
StartCoroutine(CheckRoutine());
}
IEnumerator CheckRoutine()
{
UnityWebRequest request = new UnityWebRequest("https://www.google.com/");
yield return request.SendWebRequest();
if (string.IsNullOrEmpty(request.error))
{
yesNo.text = "Yes";
}
else
{
yesNo.text = "No";
}
}
Although this works (to check of course, not actually kill the application yet). I would imagine if I just call this in the awake method of my menu manager. You would now be able to airplane mode your phone since the game isn't checking for WiFi connection anymore. Is there a better way to ensure there is internet access throughout the whole game besides calling this function every time you load a scene?
You must somehow handle the loss of connection at any time you want to DO net access from the game, handle that your real access fails. No matter how many times you check for google.com other access can still fail...
Answer by VanToRiaXVII · May 18 at 04:01 PM
The priority is always to check if you're receiving the information you're supposed to get. You should check if you haven't received the information for a while and show a "disconnected" status to the player if you go over a timeout without getting new data.
If you're making a single-player game, you'd usually get new info around 20 secs, so if you reach that timeout, it means a problem has happened and your game should take appropriate measures to let the user know. Multiplayer (co-op or pvp) games would need a much shorter timeout to realize that something has gone wrong.
Your answer
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
What properties from a HLAPI connection can be used to create a LLAPI connection? 0 Answers
Simulating a loss of internet connection 0 Answers
Parenting via Networking 0 Answers
Unity Unet Ping Time Out On Mobile 0 Answers