Godot Engine

Godot Engine

Multiplayer: Any way around port forwarding?
I'm making a 1v1 game, where one player must connect to another to play. Currently via direct IP, but I'll figure out a matchmaking system as I get the gameplay more nailed down.

Problem is, in order to play behind a router I have to set up port forwarding, now that's fine for testing, I know what I'm doing.. but lets be honest, these days people either don't know or can't be bothered to port forward. If I release my game without sorting this out I guarantee 90% of reviews are going to be "couldn't connect to my friend, doesn't work, ♥♥♥♥ game 0/10"

Does anyone have a solution for this?


Update: I've done it! I got the game on Steam and it works flawlessly!
Replaced all my RPC calls with sending packets to the steam lobby, which took a bit of figuring out, but it works perfectly! Thank you so much!
Last edited by Lucius Caesar; Nov 24, 2020 @ 7:16am
< >
Showing 1-15 of 31 comments
Valdar Oct 16, 2020 @ 4:13am 
I can't give you specific instructions on how-to with Godot, but you can research NAT Punch-through and that should get you going in the right direction.
Lucius Caesar Oct 16, 2020 @ 4:20am 
Originally posted by Valdar:
I can't give you specific instructions on how-to with Godot, but you can research NAT Punch-through and that should get you going in the right direction.
Actually that was the first thing I looked for but couldnt find any Godot specific implementations, mostly just finding people asking if Godot supports it,and being told no. But I'll give it another search. Thanks
Last edited by Lucius Caesar; Oct 16, 2020 @ 4:26am
Romløk Oct 16, 2020 @ 8:08am 
The solution you're looking for is probably a STUN/TURN server to act as an intermediary.
Unfortunately, Godot's networking doesn't have support for that in the engine yet, though there is a proposal to add it: https://github.com/godotengine/godot-proposals/issues/434
Lucius Caesar Oct 16, 2020 @ 8:22am 
hmmm, sounds like even if Godot eventually supports NAT punchthrough (and I think STUN/TURN is either the same thing or similar? it's explanation looks similar to me) I'll need a separate server to mediate the p2p connections which I was hoping to avoid... I might have to just make it based on a master server, treat it like an MMO almost but I was hoping to avoid having to rent big servers... at least it would mean I can handle matchmaking more easily I guess.

Thanks for the replies.
zeeb Oct 16, 2020 @ 12:17pm 
Shouldn't Godot be able to handle P2P?
As far as I know there shouldn't be an issue with connecting through IP addresses etc.

Also, Port Forwarding is widely used across several games.
Take Counter-Strike 1.6 for example, you need to port forward if you want to host a server for other players.
Lucius Caesar Oct 17, 2020 @ 3:58am 
Originally posted by zeeb:
Shouldn't Godot be able to handle P2P?
As far as I know there shouldn't be an issue with connecting through IP addresses etc.

Also, Port Forwarding is widely used across several games.
Take Counter-Strike 1.6 for example, you need to port forward if you want to host a server for other players.
I guarantee you any game that came out today that required port forwarding and didn't at least have loads of dedicated servers ready to go as an alternative would be blasted.



port forwarding is used in a variety of older games with a dedicated fanbase, it's not viable today when people expect to just click 'start game' and have their friend join them


As for your first point... should it? I'm guessing it wouldnt be with the Enet implementation if there is a way.
Last edited by Lucius Caesar; Oct 17, 2020 @ 4:04am
The author of this thread has indicated that this post answers the original topic.
tin Oct 23, 2020 @ 7:59pm 
If you're planning on being Steam only, then this might help:
https://gramps.github.io/GodotSteam/tutorials-lobbies-p2p.html
Lucius Caesar Oct 24, 2020 @ 12:14am 
Originally posted by tin:
If you're planning on being Steam only, then this might help:
https://gramps.github.io/GodotSteam/tutorials-lobbies-p2p.html
This looks very VERY promising. Thank you so much.

Ricky Sauce Nov 5, 2020 @ 8:30am 
Since you're making a 1v1 game, I'm going to assume it's PvP based as well. It would probably be better to have clients connect to a server to delegates packets to each other. Otherwise, you're giving out IP addresses willy nilly which will likely cause issues in the future when people start abusing the fact they can get their opponents IP address and do anything from nothing to ddosing them.

I'd be more worried about that than assuming my users are too dumb to port forward.
tin Nov 5, 2020 @ 2:52pm 
Originally posted by Ricky Sauce:
Since you're making a 1v1 game, I'm going to assume it's PvP based as well. It would probably be better to have clients connect to a server to delegates packets to each other. Otherwise, you're giving out IP addresses willy nilly which will likely cause issues in the future when people start abusing the fact they can get their opponents IP address and do anything from nothing to ddosing them.

I'd be more worried about that than assuming my users are too dumb to port forward.

Yeah - nah. Having to forward ports is a much bigger problem. For starters, not everyone has a public IP to begin with, especially on mobiles or residential grade internet in Asian countries. If the NAT is done at your ISP, you're not going to be forwarding any ports.
Valdar Nov 10, 2020 @ 6:54pm 
If you want reliable P2P without port-forwarding behind NAT enabled routing, you’ll need a public IP server. Then you need to implement Hole Punching, sometimes called NAT Punch-through. This is basically some p2p code on your client-side software/game and a rendezvous protocol service on the server. Several ISP-type companies offer such a service for a reasonable fee. I know it can be done through DockerHub (maybe with a standard free account; I’m not sure if you need a premium account or not). As mentioned, the server could be Steam, and they will do the dirty work for you. Also, you could possibly even do it with Dynamic DNS, but I’ve never tried it.
For anyone who is interested, here is an excellent article by Bryan Ford explaining pretty much everything you need to know regarding how and why this is necessary in P2P across NAT (complete with diagrams and references, including RFCs).
https://bford.info/pub/net/p2pnat/
Lucius Caesar Nov 22, 2020 @ 8:19am 
Originally posted by CheekyG46:
Sorry if this is a little late but you could consider telling your users about reverse proxies like Hamachi or Ngrok. Otherwise, you would need to probably rent a server that all games run from or implement hole-punching like others have said. Do note that Ngrok doesn't support UDP natively though.
Thanks for the response, I do appreciate it. I'm actually trying out tin's suggestion of using Steamworks p2p or lobbies via the GodotSteam module. Only just got my Steam Dev account sorted and GodotSteam compiled so starting tomorrow I'll be trying that out, Will definitely update here how that goes :) (completely unrelated.. seeing my game in my steam library is freaking wild!)
Last edited by Lucius Caesar; Nov 22, 2020 @ 8:20am
Lucius Caesar Nov 24, 2020 @ 7:15am 
Originally posted by tin:
If you're planning on being Steam only, then this might help:
https://gramps.github.io/GodotSteam/tutorials-lobbies-p2p.html


I've done it! I got the game on Steam and it works flawlessly!
Replaced all my RPC calls with sending packets to the steam lobby, which took a bit of figuring out, but it works perfectly! Thank you so much!
tin Nov 24, 2020 @ 3:22pm 
Nice...
Valdar Nov 24, 2020 @ 4:25pm 
Hey, that's awe
some that you got it working. Grats!
< >
Showing 1-15 of 31 comments
Per page: 1530 50

Date Posted: Oct 16, 2020 @ 4:02am
Posts: 31