Skip to main content

Overview

Godot provides low-level networking implementations through ENet for reliable UDP communication and WebSocket for web-based networking. These form the foundation of the high-level multiplayer system.
Most games should use the high-level multiplayer API, but understanding the low-level implementations helps optimize network performance.

ENetMultiplayerPeer

ENet provides reliable UDP communication with low latency, making it ideal for real-time multiplayer games.

Creating a Server

Creating a Client

Use the same compression mode on both client and server for compatibility.

ENet Configuration

Compression

ENet supports packet compression to reduce bandwidth:
Compression Comparison:

Transfer Channels

ENet supports multiple channels for organizing traffic:
Channel Usage:
  • Channel 0: Critical game state (reliable)
  • Channel 1: Position updates (unreliable ordered)
  • Channel 2: Chat messages (reliable)
  • Channel 3: Voice data (unreliable)

Bandwidth Throttling

WebSocketMultiplayerPeer

WebSocket enables multiplayer in web browsers and provides cross-platform compatibility.

WebSocket Server

WebSocket Client

WebSocket is required for HTML5 exports but has higher latency than ENet. Use ENet for native builds.

PacketPeer

Both ENet and WebSocket implement the PacketPeer interface for raw packet sending:

Low-Level ENet Connection

For complete control, use ENetConnection directly:

Custom Protocol Implementation

Implement custom protocols using StreamPeer:

NAT Traversal

For peer-to-peer connections through NAT:
UPNP may not work on all routers. Consider using dedicated relay servers for reliable connectivity.

Performance Optimization

Packet Batching

Connection Monitoring

Best Practices

Use ENet for native games (lower latency), WebSocket for web exports and cross-platform compatibility.
Use compression for text and repeated data, but disable for already compressed content (images, audio).
Track RTT, packet loss, and bandwidth usage to identify network issues early.
Handle temporary disconnections gracefully with automatic reconnection attempts.
Separate traffic types into different channels to prevent head-of-line blocking.

See Also

Networking Overview

Learn networking fundamentals

High-Level Multiplayer

Use spawning and synchronization

HTTP Requests

Make web API calls