kuligs2
So playing around with VM and having other issues, ive concluded on linux its really tricky to get "local" ip..
First of all if the hostname environment is not set then you wont be able to get hostname with str(OS.get_environment("HOSTNAME"))
Secondly even if you do manage to get hostname, it wont resolve the ip for some reason using IP.resolve_hostname_addresses(host_name_var,1)
or IP.resolve_hostname(host_name_var,1)
One thig that works is that is:
var ip
for address in IP.get_local_addresses():
if (address.split('.').size() == 4):
ip=address
print("my ip: ", ip)
But.. as people get more advanced in life, they dont settle with just one network interface.. some might run virtual machines and other things like containers and dockers.. these things will create virtual network interfaces that will have their own local IP.. so you will not know for sure whic one is the "computer" and not some virtual thing..
As for the hostname, mintVM, gives me the hostname when i use:
var output = []
var exit_code = OS.execute("cat",["/proc/sys/kernel/hostname"],output)
kuligs2 var ip_adress :String
if OS.has_feature("windows"):
if OS.has_environment("COMPUTERNAME"):
ip_adress = IP.resolve_hostname(str(OS.get_environment("COMPUTERNAME")),1)
elif OS.has_feature("x11"):
if OS.has_environment("HOSTNAME"):
ip_adress = IP.resolve_hostname(str(OS.get_environment("HOSTNAME")),1)
elif OS.has_feature("OSX"):
if OS.has_environment("HOSTNAME"):
ip_adress = IP.resolve_hostname(str(OS.get_environment("HOSTNAME")),1)
and as for this, this was taken from a forum, and does not work (in 4.2) on linux. Instead of "x11" use "linux"
but it still wont find your hostname, because for me i have not set the hostname environment varriable in the linux.
Also, i just read the doc, https://docs.godotengine.org/en/stable/classes/class_enetmultiplayerpeer.html#class-enetmultiplayerpeer-method-create-client
Error create_client(address: String, port: int, channel_count: int = 0,
in_bandwidth: int = 0, out_bandwidth: int = 0, local_port: int = 0)
Create client that connects to a server at address using specified port.
The given address needs to be either a fully qualified domain name (e.g. "www.example.com")
or an IP address in IPv4 or IPv6 format (e.g. "192.168.1.1")
So the localhost
in your case should/would not work.. maybe try 127.0.0.1
?? this loopback is always the same across all OSes. Im too lazy to recreate the whole enet multiplayer simple project.. and test it out