Creating network connections with Godot is simple — as long as you have the other party’s IP address, and there’s no NAT gateway involved. Unfortunately, that’s exactly the problem in most cases. You don’t know the other party’s IP, and these days, just about everyone is behind a combination wifi router/gateway/firewall with NAT.
Conceptually, NAT hole-punching is pretty simple, and this video explains how it’s done with just netcat.
In a nutshell:
listen on a particular port (e.g. 50001)
nc -u -l 50001
echo ‘hello’ | nc -u ipaddr 50001
echo ‘hole punch’ | nc -u -p 50001 ipaddr 50002
third party exchanges ip addresses
Putting it all together, player A (hosting a game) would require the game to connect to the directory server.
The directory server would list the game as something a player can now connect to.
player B (client who wants to join) will tell the directory service that it wants to connect, and will send its info
The directory server forwards the information to player A (host), player A will then send a packet to player B, and respond to the directory server
The directory server will then tell player B to go ahead and connect to player A.
Player B should be able to punch through to player A
With Godot, the connections from client to host would use ENetMultiplayerPeer.create_client(), which can specify the local port.
Godot-matcha is an addon that lets you use WebRTC for multiplayer games by handling matchmaking using WebTorrent trackers. Conceptually it’s quite an interesting, novel approach. WebTorrent uses a modified BitTorrent protocol that allows it to work with WebSockets. A WebTorrent tracker is essentially a directory service that keeps track of torrents offered by users. A …
A new version of the Inventory System is available. This release includes various refinements to existing systems to flesh out more combat-related functionality. Inventory Ammo Provider The GGAmmoProvider component is responsible for providing ammunition to equipped weapons. Previously, it only had a “simple” strategy: Creating ammunition out of thin air. The new GGAmmoProviderInventoryStrategy pulls ammunition …
Godot Engine 4.0 has been released per official announcement. With version 4.0, Godot has gone through “3+ years of breaking and rebuilding from the ground up, a complete core overhaul and a full engine rewrite, through 17 alphas, 17 betas and 6 release candidates“. The announcement post is credited to “2000+ Godot contributors.” It’s a …
Creating a UDP peer-to-peer connection
Creating network connections with Godot is simple — as long as you have the other party’s IP address, and there’s no NAT gateway involved. Unfortunately, that’s exactly the problem in most cases. You don’t know the other party’s IP, and these days, just about everyone is behind a combination wifi router/gateway/firewall with NAT.
Conceptually, NAT hole-punching is pretty simple, and this video explains how it’s done with just netcat.
In a nutshell:
Putting it all together, player A (hosting a game) would require the game to connect to the directory server.
With Godot, the connections from client to host would use ENetMultiplayerPeer.create_client(), which can specify the local port.
Here’s an older example of a signaling server: https://github.com/Faless/gd-webrtc-signalling/tree/master
Related Posts
godot-matcha: Free multiplayer without a server
Godot-matcha is an addon that lets you use WebRTC for multiplayer games by handling matchmaking using WebTorrent trackers. Conceptually it’s quite an interesting, novel approach. WebTorrent uses a modified BitTorrent protocol that allows it to work with WebSockets. A WebTorrent tracker is essentially a directory service that keeps track of torrents offered by users. A …
Inventory System v1.12 available
Crafting is here! The latest inventory system version is now available with the following features: The bug fixes:
Inventory System v1.17 available
A new version of the Inventory System is available. This release includes various refinements to existing systems to flesh out more combat-related functionality. Inventory Ammo Provider The GGAmmoProvider component is responsible for providing ammunition to equipped weapons. Previously, it only had a “simple” strategy: Creating ammunition out of thin air. The new GGAmmoProviderInventoryStrategy pulls ammunition …
Godot Engine 4.0 released!
Godot Engine 4.0 has been released per official announcement. With version 4.0, Godot has gone through “3+ years of breaking and rebuilding from the ground up, a complete core overhaul and a full engine rewrite, through 17 alphas, 17 betas and 6 release candidates“. The announcement post is credited to “2000+ Godot contributors.” It’s a …