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

  • March 12, 2025

    Inventory System 2 Alpha 3 available

    This release improves weight management. Inventories can now configure an option weight limit, and item stacking and item transfer strategies are weight-aware. The crafting demo and crafting mechanic in the inventory tour have been improved. Auto-crafting is limited to the crafting slide, so that items don’t automatically and unexpectedly get crafted while stepping through the …

  • March 11, 2025

    Update all resources after modifying a resource class

    Godot’s resources are quite powerful. However, modifying a resource class doesn’t automatically update any corresponding .tres files, unless you happen to edit a scene that uses that resource in some way. This doesn’t impact runtime behavior — the game still runs as expected. But it can impact version control and result in a messier diff …

  • Godot Game Engine Logo
    September 15, 2022

    Godot Engine 4 reaches beta

    Just a couple of days ago, Godot 4.0 alpha 17 was announced. Today, Godot Engine 4.0 beta 1 was released. Be sure to check out the announcement. There are lots of improvements across the board; rendering, lighting, physics and navigation, animation, and scripting.

  • February 25, 2024

    Inventory System v1.11 available

    The latest inventory system is now available and it focuses on multiplayer permissions. The new Access Manager component validates client requests to ensure players can’t cheat and interact with inventories they’re not supposed to be able to have access to. New features: Bug fixes:

    © 2025 GoGoGodot.io. All rights reserved.