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
ENet Configuration
Compression
ENet supports packet compression to reduce bandwidth:Transfer Channels
ENet supports multiple channels for organizing traffic:- 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 thePacketPeer interface for raw packet sending:
Low-Level ENet Connection
For complete control, useENetConnection directly:
Custom Protocol Implementation
Implement custom protocols usingStreamPeer:
NAT Traversal
For peer-to-peer connections through NAT:Performance Optimization
Packet Batching
Connection Monitoring
Best Practices
Choose the right protocol
Choose the right protocol
Use ENet for native games (lower latency), WebSocket for web exports and cross-platform compatibility.
Enable compression wisely
Enable compression wisely
Use compression for text and repeated data, but disable for already compressed content (images, audio).
Monitor network performance
Monitor network performance
Track RTT, packet loss, and bandwidth usage to identify network issues early.
Implement reconnection logic
Implement reconnection logic
Handle temporary disconnections gracefully with automatic reconnection attempts.
Use channels effectively
Use channels effectively
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