Hi, in this post I will be discussing Godot and how we can use our own UDP implementation to make online/multiplayer games.

Implementations using ENet

Godot comes with its own implementation of connectivity using its built-in ENet. It has a lot of good features, like sync data, RPC, and others that I didn’t use. Since it’s its own system, this means we have to use a Godot executable to act as the server or peer-to-peer implementation. Sometimes using these implementations can be a bit annoying and underwhelming.

Peer-to-Peer (ENet) — Godot

Peer B (Godot)
Peer A (Godot)
ENet: connect to B IP:port
ENet: connect to A IP:port
send input/state
send input/state
receive remote state
receive remote state
ENetMultiplayerPeer
Game Logic
ENetMultiplayerPeer
Game Logic

There are a lot of functions that we can do with this implementation, like very basic games and player games where data is given and received between each other.

This implementation has many weaknesses:

  • Sometimes restricted by local networks.
    • Functionality outside of the local network becomes more difficult. For example, we don’t want the player to expose their game host across the internet to another peer. It’s possible, but not ideal.
  • All of the data will come from Peer A (the host), while the rest of the peers simply join that host.
  • For simpler games, this implementation can be a good idea, but in more complex cases there’s a different approach:
    • A wrapper service acts as the middleman, assigning peers and providing a connection between them (similar to how matchmaking or relay services work). It’s the same but it has extra steps to allow online connectivity
Matchmaking / API Wrapper (e.g., Steam API, lobby system)
Relay Server (acts like VPN)
Peer B (Godot)
Peer A (Godot)
Connect via relay
Connect via relay
Forward packets
Forward packets
send input/state
send input/state
receive remote state
receive remote state
Provides peer addresses / relay info
Provides peer addresses / relay info
Friend Finder / Session Manager
Forward traffic between peers
ENetMultiplayerPeer
Game Logic
ENetMultiplayerPeer
Game Logic