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.
I’m wrapping up development on version 1 of the Inventory System, which is currently at v1.18.1. All core functionality is in place, and it provides many quality-of-life features. The guide covers and walks through most of the code base, and the demo projects show off a lot of use cases. This first version has been …
A smaller update. The inventory components now have custom icons to make it easier to tell them apart. This release also includes additional bug fixes:
When I think of video games, I generally still think of an application that is downloaded and runs on the client. Technically, that’s still the case with web-based exports from Godot Engine, since the web browser has to download the files before being able to run them. I thought maybe I could just run the …
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
Inventory System v1.18.1 available (and v2 progress update)
I’m wrapping up development on version 1 of the Inventory System, which is currently at v1.18.1. All core functionality is in place, and it provides many quality-of-life features. The guide covers and walks through most of the code base, and the demo projects show off a lot of use cases. This first version has been …
Inventory System v1.4 available
A smaller update. The inventory components now have custom icons to make it easier to tell them apart. This release also includes additional bug fixes:
Inventory System v1.8.1 available
A quick update to yesterday’s release with a few fixes:
Quickly deploying Godot games on the web with Netlify
When I think of video games, I generally still think of an application that is downloaded and runs on the client. Technically, that’s still the case with web-based exports from Godot Engine, since the web browser has to download the files before being able to run them. I thought maybe I could just run the …