A Dart implementation of UDX - reliable, multiplexed, and congestion-controlled streams over UDP.
UDX is a QUIC-inspired, UDP-based transport protocol that provides reliable, ordered delivery with advanced networking features. This Dart implementation offers the core building blocks for creating high-performance, connection-oriented communication over UDP.
- Reliable & Ordered Delivery - TCP-like reliability over UDP
- CUBIC Congestion Control - Optimal throughput with adaptive bandwidth utilization
- Multi-layer Flow Control - Both connection and stream-level flow control
- Connection Migration - Seamless network path changes for mobile applications
- Path MTU Discovery - Automatic optimization of packet sizes
- Packet Pacing - Smooth network utilization to prevent bursts
- Stream Multiplexing - Multiple concurrent streams per connection
- Event-Driven Architecture - Responsive, asynchronous I/O
Add this package to your pubspec.yaml
:
dependencies:
dart_udx: ^0.3.0
Then run:
dart pub get
import 'dart:io';
import 'package:dart_udx/udx.dart';
void main() async {
final udx = UDX();
final socket = await RawDatagramSocket.bind(InternetAddress.anyIPv4, 8080);
final multiplexer = UDXMultiplexer(socket);
print('UDX server listening on port 8080');
multiplexer.connections.listen((connection) {
print('New connection from ${connection.remoteAddress}');
connection.on('stream').listen((event) {
final stream = event.data as UDXStream;
stream.data.listen((data) {
print('Received: ${String.fromCharCodes(data)}');
stream.add(data); // Echo back
});
});
});
}
import 'dart:io';
import 'dart:typed_data';
import 'package:dart_udx/udx.dart';
void main() async {
final udx = UDX();
final socket = await RawDatagramSocket.bind(InternetAddress.anyIPv4, 0);
final multiplexer = UDXMultiplexer(socket);
final connection = multiplexer.createSocket(udx, '127.0.0.1', 8080);
await connection.handshakeComplete;
final stream = await UDXStream.createOutgoing(
udx, connection, 1, 2, '127.0.0.1', 8080
);
// Send data
final message = 'Hello, UDX!';
await stream.add(Uint8List.fromList(message.codeUnits));
// Receive echo
stream.data.listen((data) {
print('Received: ${String.fromCharCodes(data)}');
stream.close();
connection.close();
});
}
UDX follows a layered architecture for maximum flexibility:
UDXMultiplexer
- Manages I/O for multiple connections over a single UDP socketUDPSocket
- Represents a single logical connection with handshake and flow controlUDXStream
- Provides reliable, ordered data streams with congestion control
This design enables advanced features like connection migration, where connections can seamlessly move between network interfaces.
- Connection Migration - Move connections between network interfaces without dropping
- Flow Control - Prevent overwhelming receivers at both connection and stream levels
- Congestion Control - CUBIC algorithm with slow start, congestion avoidance, and fast recovery
- Error Recovery - Automatic retransmission and duplicate detection
- Performance Monitoring - Built-in RTT, throughput, and congestion window metrics
For detailed API documentation, advanced usage examples, and best practices, see the Developer Guide.
UDX is designed for high-performance applications:
- Zero-copy packet processing where possible
- Efficient memory management with configurable buffers
- Packet pacing to maximize network utilization
- Adaptive MTU discovery for optimal packet sizes
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
This project is licensed under the MIT License - see below for details.
MIT License
Copyright (c) 2025 - Stephan M. February
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
This implementation is inspired by the original UDX protocol and incorporates concepts from QUIC and modern transport protocol design.