Godot Multiplayer IP Configuration

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

I am currently making a game that requires a direct connection across separate computers. Here are the relevant parts of my code:

const PORT = 5820
const MAX_PLAYERS = 8
func setup_host():
    var peer = NetworkedMultiplayerENet.new()
	peer.create_server(PORT, MAX_PLAYERS)
	main.get_tree().network_peer = peer
	is_server = main.get_tree().is_network_server()

func setup_client():
	var peer = NetworkedMultiplayerENet.new()
	peer.create_client(get_my_ip_address(), PORT)
	main.get_tree().network_peer = peer

const my_number = 9 # I have tried every single one, but 9 is the index of what the preferred connection is for windows (I used terminal to find this)
func get_my_ip_address(my_number):
	return IP.get_local_addresses()[my_number]

I have successfully tested this when running two instances of the application on my computer (same computer, and any ip address worked also). I have not yet tried local multiplayer on separate computers.

I cannot figure out how to make this work with separate computers on different networks. I have tried every single entry in IP.get_local_addresses() (which itself is a combination of different IPV4 [local] and IPV6 [internet] connections). I am also using a windows computers, and my friend is on the same platform. I don’t know if its just the platform, my code, or the windows firewall blocking the connection (I highly doubt its the firewall).

I have a few theories on how to solve this issue, but I can’t make them work.

  • The first is to instead put a link like www.my_site.com instead of the IP address (I read that somewhere), but games like minecraft using direct connect just use IP addresses and Port Numbers to connect with each other, so I know there has to be a way around this. (Take a look at the last link in this chain, because I think that’s the only I way I can think of using an ip and port in a web address.)
  • The second is not using NetworkedMultiplayerENet, but again, I have not found anything that uses explicitly direct connect (I.E. not a web address). If it does require a web connection in the end and I do need to connect to a website, I want it to be free and, if acting as a server, running at all times.

Please tell me ways on how to solve this. I have looked everywhere and have come up empty handed. I promise I’ll make a youtube video or something once I learn the solution, because honestly, this stuff should be more accessible.

Here are some links if you are new to the issue:

GODOT tutorial on how to do multiplayer (fails to explain what IP to use): High-level multiplayer — Godot Engine (stable) documentation in English

Says to use vpn/paid thing to host server, but I want a direct connection: https://forum.godotengine.org/65774/how-to-connect-to-a-server-outside-of-local-network

Gives several ways to solve the problem, a good lead, however, the tutorial inside this link on Direct Connection is the link below, and it lacks crucial information: https://forum.godotengine.org/43665/how-connect-two-device-with-live-server-not-localhost-godot

This one literally explains everything, but they fail to explain what IP to use: Godot dedicated server tutorial | Tom Langwaldt's Blog

It should also be noted that every multiplayer godot tutorial I have ever seen either tests it on the same computer or on a local network, never in separate locations with separate computer with separate web connections.

This one looks promissing, however, I haven’t tested it out yet, I will respond to this Q&A chain when I find the solution: Reddit - Dive into anything

Thank you so much for your help

:bust_in_silhouette: Reply From: Wakatta

Port forwarding or dedicated servers are the answers you’re looking for also look at P2P networks.

Simply put the question is beyond the scope of a Godot question and to be honest there is no one size fits all because everyone’s network configuration is different

  • What router are you using?
  • Is your LAN part of another LAN?
  • Are you connected to a VPN
  • Is your connection through a proxy server?
  • Can you do NAT punching?
  • Is your PC policy restricted by an administrator?

To think one can just go online an connect to another person’s computer unrestricted is a dream meant for another world.

:bust_in_silhouette: Reply From: arabask

or the windows firewall blocking the connection (I highly doubt its the firewall).

for me it was the firewall and your code seems fine
I check this page to allow access for some apps by windows defender:

I just allowed everything nammed godot engine and it worked
but there is a lot of possible problems

:bust_in_silhouette: Reply From: Beatrix

is the computer is on separate lan/wifi? if yes You Need

Port Forwading

:bust_in_silhouette: Reply From: MadMelon999

I figured out the solution of how to use direction connections across separate computers and networks. There are 2 main points to this:

  • The first is that you need Port Forwarding (basically telling your wifi router to accept certain connections). I am not too familiar with this topic, but there are several resources to use if you just look them up or use my previous links.

  • The second is the Firewall. I was definitely wrong in thinking that the firewall would be a problem, because after checking a lot of specs, I realized all private and public Godot connections were severed automatically by my computers

But, even though I found the answer, I still don’t like port forwarding. I want it to be a simple process for the user to create/connect to multiplier games, not a weird process where you have to setup your own home as a public server.

Godot Steam is the solution here (at least for me). It has excellent network debugging tools that literally let you use their services without actually submitting a game! I was literally able to use their networking features while using my debugger for Godot. I don’t think its allowed to use this service for a published game, but that’s for you to figure out.

Attached are some links if you want to start using GodotSteam (which is not easy to start, but gets easier down the road). Here are some steps

I know this isn’t the clean-cut direct-connect solution I was looking for, but I hope this helps if you guys had the same problem as me.