Check if user has a internet connection on mobile device

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By desik
:warning: Old Version Published before Godot 3 was released.

Hi!

For my mobile game I need to check if user has a internet connection.
It will be used to decide is should show him a form to send a leaderboard entry to the server. Is there any easy way to do such check? Maybe some online/offline events like on the native Android?

:bust_in_silhouette: Reply From: ingo_nikot

you could just try to connect to the server with the leaderboard.
If no connection: do nothing or tell the player
If connection possible: update leaderboard

Check out HTTP client class:
http://docs.godotengine.org/en/stable/learning/features/networking/http_client_class.html

this code snippet checks for a successful connection

:bust_in_silhouette: Reply From: Çağdaş Çağlak

You can use this script which is in my Github profile. I have explained “How can I implement?”

Merhaba Çağdaş bey.

I am using Godot 3.2.3. I get the following error. how do i solve the problem? I need to constantly check the internet connection for a game.

HTTPRequest is processing a request. Wait for completion or cancel it before attempting a new one.

This error comes when the internet connection is lost.

_resolve_hostname: getaddrinfo failed! Cannot resolve hostname.

When I run the game without connection:
_resolve_hostname: getaddrinfo failed! Cannot resolve

maxiproduksiyon | 2020-11-16 16:48

Did you solve this problem?

pclight | 2021-03-08 14:22

Hi,

I couldn’t try it on Godot 3.2.3. You have to choose trusted hostname which has quick response such as www.google.com. I think, the problem is your host. It isn’t resolving by Godot.

Çağdaş Çağlak | 2021-03-08 19:06

Hi, thank you for your answer.
I also use www.google.com. It gives this error when disconnected and continues until I reconnect. Connection quality can also be a consideration.

pclight | 2021-03-09 09:21