How to connect to a server outside of local network?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Sprowk

I’m trying to create a game where one player starts a server and others enter his IP address and connect to him. I managed to get it working for localhost and also for 2 computers at the same Wifi.

The problem is when I try to do it with my friend (who is connected to a different network) he can’t connect to my server. This is part of my autoload script:

func host_game(new_player_name):
	player_name = new_player_name
	var host = NetworkedMultiplayerENet.new()
	host.create_server(DEFAULT_PORT, MAX_PEERS)
	get_tree().set_network_peer(host)


func join_game(ip, new_player_name):
	player_name = new_player_name
	var client = NetworkedMultiplayerENet.new()
	client.create_client(ip, DEFAULT_PORT)
	get_tree().set_network_peer(client)

Is something wrong with the code, router or am I just entering the wrong IP? I tried to enter IP from websites like whatsmyip and also ipv4 from command ipconfig.

Edit: I found a good answer here: Private vs Public IP Addresses - Archive - Godot Forum but couldn’t set up my router so I looked further. Found free hosting site for Godot games ( https://gotm.io/ ). Easy to upload but still can’t figure out how to enable multiplayer. Any ideas?

Found free hosting site for Godot games ( https://gotm.io/ ). Easy to upload but still can’t figure out how to enable multiplayer. Any ideas?

That website won’t provide hosted multiplayer servers (or a way to avoid port forwarding if you’re hosting a server on your own PC).

Calinou | 2020-03-31 07:23

Okay so I tried to do it with port forwarding (port 10567). Disabled all firewalls on windows 10. Also setup static IP on my computer and set the wifi as private. Still my friend (client) couldn’t connect to me (server). Any ideas? I’ll probably ask this as a new question though.

Sprowk | 2020-03-31 19:39

:bust_in_silhouette: Reply From: StrangeCube

You have to either port forward the host or use a virtual network, I use Hamachi to do this
you can get hamachi at (VPN.net) it hosts a virtual network that will trick games into thinking you and your friend are on the same local network.

I solved it
It seems that we have to look closely at the IP of the PC directly in the ethernet state, there is the real IP while Godot, due to my bad configuration, throws me another IP so that it is already there
In addition to that we must give permissions to the app before exporting with godot
Internet and Access network satate
With that the connection between pc and android is successful greetings!

lurgx | 2022-06-04 09:10