How to get the response time of an ip?

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

How can I get the response time of a connection?

ping 216.58.202.68
PING 216.58.202.68 (216.58.202.68) 56(84) bytes of data.
64 bytes from 216.58.202.68: icmp_seq=1 ttl=55 time=43.9 ms
64 bytes from 216.58.202.68: icmp_seq=2 ttl=55 time=43.9 ms

I need the response time between two machines, to decide which server to connect to.

:bust_in_silhouette: Reply From: exusr

The only way I could solve this problem was by running the system command, I don’t know if there is any difference with Windows or Mac

var output = []
OS.execute('ping', ['-w', '3', 'godotengine.org'], true, output)
for line in output:
	print(line)

This is a nice solution. However, it’s platform dependant; if the platform doesn’t have a similar version of ping, you’ll have problems. :-/

Ertain | 2019-03-19 23:55

For similar version of ping do you mean the command or the tool itself? can you give me an example please? I’m interested because I’m currently facing the same problem

exusr | 2019-03-20 10:37

I’m referring to the “ping” command. While it’s similar in Windows, MacOS, and Linux, I’m sure there are a few differences. For instance, on Windows, the stock ping command (without any other options) will send an ICMP to an address four times, and then exit. On Linux (provided you’re using the version found in Fedora, Debian, and the like) it’ll keep sending ICMP until you forcibly exit the command. The code you recommended, utilizing the “-w” option, seems to be supported across each version of ping. So as long as the user doesn’t stray far from your recommendation, they should be fine.

Ertain | 2019-03-22 03:54