Go, Go, Godot!
  • 0

Creating a UDP peer-to-peer connection

November 16, 2023

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.

Here’s an older example of a signaling server: https://github.com/Faless/gd-webrtc-signalling/tree/master

gdscriptgodotnetworking
Posted in Godot.
Share
Previousgodot-matcha: Free multiplayer without a server
NextSuper Godot Galaxy Concept

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Related Posts

  • January 3, 2024

    2D Fog Effect Shader Tutorial

    The shader used in the tutorial: https://godotshaders.com/shader/2d-fog-overlay-2/

  • July 30, 2024

    Inventory System v1.15 available

    This inventory system release refines a lot of architecture guide sections based on customer feedback and adds over 100 additional pages to the PDF guide. Features: Bug fixes:

  • April 1, 2023

    Introducing GodotBuilder: Custom Export Templates built on demand

    Need optimized export templates with PCK encryption support but don’t want to have to set up a build pipeline or download the entire compilation toolchain on your computer? Well, now it is. Fill out the form, checkout, and we’ll email you the download link after the compilation completes. Compilation may take 30 minutes to 3 …

  • Godot Game Engine Logo
    September 14, 2023

    Building UIs in Godot 4

    Here’s a collection of tutorials that are helpful if you’re new to using Control and Container nodes to create UIs in Godot 4. The Game Dev Artisan video covers creating a simple UI with a reload indicator for a simple 2D tank game: Clear Code’s 11+ hour Ultimate Introduction to Godot 4 has a chapter …

    © 2025 GoGoGodot.io. All rights reserved.