ENet
-
Free and open-source.
-
Designed for reliability over UDP with low latency.
-
Advantages :
-
Supports reliability and flow control over UDP.
-
Highly optimized for large-scale multiplayer games, especially for low-latency, real-time state communication.
-
Good scalability, supporting multiple clients.
-
Solid documentation and active community.
-
-
Disadvantages :
-
Slightly more complex implementation compared to other solutions due to fine-grained control.
-
-
License :
-
MIT License.
-
-
ENet .
-
ENet .
Packet Flags: ENet
-
ENET_PACKET_FLAG_RELIABLE:
-
"packet must be received by the target peer and resend attempts should be made until the packet is delivered".
-
-
ENET_PACKET_FLAG_UNSEQUENCED:
-
"packet will not be sequenced with other packets. not supported for reliable packets".
-
-
ENET_PACKET_FLAG_UNRELIABLE_FRAGMENT:
-
"packet will be fragmented using unreliable (instead of reliable) sends if it exceeds the MTU".
-
Packet Flags: Godot
-
FLAG_RELIABLE
-
Mark the packet to be sent as reliable.
-
-
FLAG_UNSEQUENCED
-
Mark the packet to be sent unsequenced (unreliable).
-
-
FLAG_UNRELIABLE_FRAGMENT
-
Mark the packet to be sent unreliable even if the packet is too big and needs fragmentation (increasing the chance of it being dropped).
-
-
switch (get_transfer_mode()) { case TRANSFER_MODE_UNRELIABLE: { packet_flags = ENET_PACKET_FLAG_UNSEQUENCED | ENET_PACKET_FLAG_UNRELIABLE_FRAGMENT; channel = SYSCH_UNRELIABLE; } break; case TRANSFER_MODE_UNRELIABLE_ORDERED: { packet_flags = ENET_PACKET_FLAG_UNRELIABLE_FRAGMENT; channel = SYSCH_UNRELIABLE; } break; case TRANSFER_MODE_RELIABLE: { packet_flags = ENET_PACKET_FLAG_RELIABLE; channel = SYSCH_RELIABLE; } break; }
ENet Reliable
-
ENet is based on UDP, which does not guarantee packet delivery by default. To fix this, ENet implements its own reliability system:
-
ACKs (acknowledgment) and Retransmissions :
-
Each reliable packet has a unique sequence number.
-
When the receiver gets a packet, it sends an ACK confirming receipt.
-
If the sender does not receive an ACK in time, it retransmits the packet.
-
This continues until the packet is confirmed.
-
-
Dynamic Timeout :
-
ENet measures Round-Trip Time (RTT) and dynamically adjusts the retransmission time for lost packets.
-
Reduces unnecessary retransmissions and improves performance on unstable networks.
-
-
Example of ENet reliability :
-
Client sends P1, P2, P3
-
Server receives P1 and P3, but P2 is lost
-
Server sends ACKs for P1 and P3, but not P2
-
Client notices P2 was not acknowledged and retransmits it
-
Server receives P2 and sends an ACK
-
ENet Reliable vs TCP
-
TCP :
-
Reliable, guarantees ordered delivery without loss, retransmitting packets as needed. But it has more overhead and may have higher latency due to congestion control and acknowledgments.
-
-
ENet (reliable) :
-
ENet reliable is generally faster than TCP in most scenarios where it is supported.
-
Uses UDP as a base, but implements reliability with optional retransmissions and ordering. It is lighter and faster than TCP for games and low-latency networks, as it avoids some of TCP's restrictions, such as global congestion control and head-of-line blocking.
-
How does ENet avoid Head-of-Line Blocking?
-
ENet solves this problem in three main ways:
-
Multiple Channels
-
In ENet, packets can be sent on different channels within the same connection.
-
If a reliable packet is lost, only packets on that specific channel wait for retransmission.
-
Other channels continue sending packets unaffected.
-
Example:
-
Channel 0 sends P1, P2, P3
-
Channel 1 sends A1, A2, A3
-
If P2 (from Channel 0) is lost, only P3 waits. A1, A2, and A3 continue normally!
-
Result: Less delay, smoother communication
-
-
-
Retransmission without blocking other packets
-
ENet only retransmits lost packets at the channel level, without blocking the delivery of independent packets.
-
TCP, on the other hand, must guarantee global order, so a single lost packet can block everything.
-
-
Custom reliability control
-
In TCP, all packets are reliable and ordered.
-
In ENet, you can mix reliable and unreliable packets, choosing when to guarantee delivery and when to prioritize speed.
-
-
-
-
-
"When would you choose to use TCP then?"
-
Standard and compatible environment :
-
TCP is natively supported by any operating system and does not require an extra library like ENet.
-
-
Works well with firewalls and NAT :
-
Since it uses established connections, TCP has fewer problems with firewalls and NAT than UDP.
-
-
Transmission of large and continuous data :
-
For things like HTTP, downloads, file streaming, TCP is optimized to ensure everything arrives without loss and efficiently.
-
-
Less manual work :
-
With TCP, you don't need to manage retransmissions, congestion control, or implement your own reliability logic. It handles everything automatically.
-
-
-
Verdict :
-
ENet appears superior to TCP in almost all scenarios where it is supported, especially for online games, VoIP, and other applications requiring low latency.
-
Despite ENet's advantages, TCP still has its uses, mainly because it is native across all platforms and networks.
-
Universal compatibility – TCP works without additional libraries, while ENet requires implementation.
-
Works better with firewalls and NAT – Many networks block UDP (the base of ENet), while TCP is always allowed.
-
Use in non-interactive applications – For HTTP, downloads, file streaming, TCP works very well and is already optimized for that.
-
-
KCP (Fast and Reliable UDP Library)
-
KCP is a popular library for UDP focused on fast and reliable connections, widely used in games and network applications that require low latency.
-
Advantages :
-
Easy to integrate and offers customizable settings for flow control and packet loss recovery. It is a lightweight alternative to QUIC, maintaining good performance.
-
Excellent for high-latency and packet-loss environments, as it is designed to maintain reliability without sacrificing performance.
-
Widely used in games that require good scalability.
-
Simple implementation and easy to integrate.
-
-
Disadvantages :
-
Does not have built-in security and may require manual tuning for scalability and optimal traffic configuration.
-
Lacks advanced network control features like ENet, such as packet ordering or finely adjustable flow control.
-
-
Ideal Scenarios :
-
Multiplayer games and applications requiring low latency and reliable transmission over networks without built-in encryption.
-
Ideal for games needing reliable communication without the costs and complexity of a protocol like TCP. KCP is efficient in MMOs where latency is critical, but some packet loss can be tolerated.
-
QUIC (Quick UDP Internet Connections)
-
Developed by Google and now an IETF standard, QUIC is a UDP-based protocol that offers built-in reliability and security features (e.g., TLS encryption).
-
Advantages :
-
High scalability for multiple users, congestion control, and lost packet recovery, all with very low latency. It is one of the best options for reliable and secure data transmission over UDP.
-
-
Disadvantages :
-
More complex to implement than ENet and other libraries. Also, built-in security can require more computational resources compared to lighter solutions.
-
-
Ideal Scenarios :
-
Low-latency applications with high scalability, such as video streaming, multiplayer games, or secure web connections.
-
-
License :
-
Varies by library, but Quiche, for example, is licensed under the BSD license.
-
Reliable UDP (RUDP)
-
RUDP is a UDP extension that implements reliability, providing packet acknowledgment and retransmission while maintaining the simplicity of the protocol.
-
Advantages :
-
Offers more control over data transmission than pure UDP but with less overhead than TCP. Facilitates scalable implementation, as it has flow control and packet acknowledgment.
-
-
Disadvantages :
-
RUDP libraries can be more complex and vary in efficiency. Basic reliability may not be sufficient for data-intensive use cases.
-
-
Ideal Scenarios :
-
Applications that need more guaranteed delivery than pure UDP but do not require the full complexity and overhead of TCP.
-
-
License :
-
License varies depending on implementation, but many are MIT or BSD.
-
Several free implementations are available, especially on GitHub, although RUDP is more of a technique than a single library.
-
WebRTC (Web Real-Time Communication)
-
WebRTC enables real-time communication via UDP using data channels. It is widely used in browsers and supports NAT traversal features.
-
WebRTC .
-
Harder to implement than WebSockets and not necessary if you only need data exchange.
-
WebRTC explanation in 100 seconds .
-
Interesting.
-
-
WebRTC is a technology that enables real-time communication of audio, video, and data directly between browsers or devices without intermediate servers.
-
It is especially useful for peer-to-peer communication and is widely used in video and voice call applications.
-
It has low latency, making it ideal for real-time communication like video calls and fast file sharing.
-
Advantages :
-
Scalable and very useful for peer-to-peer connections. Provides built-in encryption and is free on local networks and easy to configure between browsers.
-
-
Disadvantages :
-
Focused on peer-to-peer connections, which limits use in centralized server architectures. NAT traversal overhead may add latency.
-
-
Ideal Scenarios :
-
Applications requiring P2P communication and moderate scalability, such as browser games or video/audio apps.
-
-
License :
-
Varies depending on implementation, but most browsers that support WebRTC use permissive licenses like BSD.
-
WebRTC is a free standard with open-source implementations in browsers and communication frameworks.
-
Comparison with WebSockets
-
Video call comparison between WebSockets and WebRTC .
-
Very cool.
-
-
Harder to implement than WebSockets and not necessary if you only need data exchange.
-
WebRTC uses technologies like UDP to transmit data, which can result in lower latency compared to TCP (protocol used by WebSockets), especially on unstable networks.
Usage Examples
-
Video calls and Voice (VoIP).
-
File sharing.
-
Real-time games.
gRPC with UDP (non-native)
-
gRPC is a high-performance RPC library that usually works over HTTP/2 but can be adapted for UDP in some cases.
-
Advantages :
-
Since gRPC is widely adopted, adapting it to UDP in microservices can allow fast calls between services, with scalability in distributed systems.
-
-
Disadvantages :
-
Not natively UDP-based, so it requires adaptations. Scalability and performance may vary depending on the level of customization.
-
-
Ideal Scenarios :
-
Microservice environments requiring low latency but that can forgo full reliability and robust sequencing.
-
-
License :
-
Apache License 2.0.
-
gRPC is free and open-source, but adaptations are needed for use with UDP, which can be done without additional costs.
-
Lidgren.Network
-
Lidgren.Network is a network library aimed at games and is a reliable solution over UDP. It is written in C# and is popular for games requiring high performance and low latency.
-
Advantages :
-
Support for reliable connections and real-time communication.
-
Easy to integrate and highly optimized for game networks.
-
Designed for games with a high number of simultaneous users, with scalability capabilities.
-
-
Disadvantages :
-
Focused on C#, which may be a limitation if you are developing in another language.
-
-
Ideal Scenario :
-
Perfect for MMOs written in C#, especially on platforms like Unity, where Lidgren can be easily integrated with the game engine.
-
-
License :
-
MIT License
-
RakNet
-
A network library widely used in multiplayer games, supporting many players and features aimed at MMOs.
-
License :
-
Originally open-source under the MIT license, but later acquired by Oculus (Facebook), and the latest version is available under a commercial license.
-