ChunkStream is a high-performance C++ library for reliable UDP-based data streaming with automatic chunking and reassembly. It provides robust mechanisms for transmitting large data frames over UDP with built-in error detection, retransmission.
- Large Data Frame Transmission: Automatically chunks large data into UDP-sized packets and reassembles them at the receiver
- Reliable UDP Communication: Built-in packet loss detection and automatic retransmission requests
- High Performance: Optimized for low-latency, high-throughput data streaming
- Memory Pool Management: Efficient memory allocation with pre-allocated buffer pools
- Thread Safety: Multi-threaded design with thread pool for concurrent packet processing
- Configurable Parameters: Adjustable MTU size, buffer sizes, and timeout settings
- Real-time Monitoring: Built-in statistics tracking for performance analysis
- Sender: Transmits large data frames by splitting them into UDP packets with sequence information
- Receiver: Receives UDP packets, reassembles them into original data frames, and requests retransmission for missing packets
- Chunks: Individual UDP packets containing part of a larger data frame with header information
- Memory Pools: Pre-allocated memory buffers for efficient packet and frame management
- C++17 compiler
- CMake 3.10 or higher
- ASIO library (standalone or Boost.ASIO)
-
Install prerequisites:
- Visual Studio 2019 or later
- CMake 3.10+
vcpkg install asio:x64-windows -
Clone the repository:
git clone https://github.com/your-org/libchunkstream-cpp.git cd libchunkstream-cpp
-
Build the library:
mkdir build cd build cmake .. -DCMAKE_TOOLCHAIN_FILE=[vcpkg root]/scripts/buildsystems/vcpkg.cmake cmake --build . --config Release cmake --build . --config Debug
-
Install prerequisites:
sudo apt-get update sudo apt-get install build-essential cmake libasio-dev
-
Clone the repository:
git clone https://github.com/your-org/libchunkstream-cpp.git cd libchunkstream-cpp -
Build the library:
mkdir build cd build cmake .. make -
Install the library (optional):
sudo make install
This will install the library and headers to your system directories, typically under
/usr/local/.
#include "chunkstream/sender.h"
#include <vector>
#include <iostream>
int main() {
// Create sender with target IP, port, and optional parameters
chunkstream::Sender sender("192.168.1.100", 5555, 1500, 50, 10485760);
// Start sender in background thread
std::thread sender_thread([&sender]() {
sender.Start();
});
// Prepare data to send
std::vector<uint8_t> large_data(5000000); // 5MB data
// Fill with your data...
// Send data frame
sender.Send(large_data.data(), large_data.size());
std::cout << "Data sent successfully" << std::endl;
// Cleanup
sender.Stop();
if (sender_thread.joinable()) {
sender_thread.join();
}
return 0;
}#include "chunkstream/receiver.h"
#include <iostream>
#include <vector>
int main() {
// Data reception callback
auto onDataReceived = [](const std::vector<uint8_t>& data, std::function<void()> release) {
std::cout << "Received data frame of size: " << data.size() << " bytes" << std::endl;
// Process your data here...
// Important: Call release when done processing
release();
};
// Create receiver with port and callback
chunkstream::Receiver receiver(5555, onDataReceived, 1500, 50, 10485760);
std::cout << "Starting receiver on port 5555..." << std::endl;
// Start receiver (blocking call)
receiver.Start();
return 0;
}// Sender with custom parameters
chunkstream::Sender sender(
"192.168.1.100", // Target IP
5555, // Target port
9000, // MTU size (jumbo frames)
100, // Buffer size (number of concurrent frames)
50000000 // Maximum data size per frame (50MB)
);
// Receiver with custom parameters
chunkstream::Receiver receiver(
5555, // Listen port
callback, // Data received callback
9000, // MTU size
100, // Buffer size
50000000 // Maximum data size per frame
);| Parameter | Description | Default | Recommended Range |
|---|---|---|---|
| MTU | Maximum Transmission Unit size | 1500 | 1500-9000 |
| Buffer Size | Number of concurrent frames in memory | 10 | 10-100 |
| Max Data Size | Maximum size per data frame | 0 (unlimited) | 1MB-100MB |
| Port | UDP port for communication | User-defined | 1024-65535 |
// Small MTU, frequent transmission
chunkstream::Sender sender(ip, port, 1500, 10, max_size);// Large MTU (if network supports), larger buffers
chunkstream::Sender sender(ip, port, 9000, 100, max_size);// Smaller buffer sizes for memory-constrained environments
chunkstream::Receiver receiver(port, callback, 1500, 20, 5000000);// Monitor transmission statistics
std::cout << "Frames received: " << receiver.GetFrameCount() << std::endl;
std::cout << "Frames dropped: " << receiver.GetDropCount() << std::endl;
// Flush pending frames (cleanup)
receiver.Flush();The library includes a comprehensive test application for data integrity verification and performance analysis.
# Display help and usage information
./chunkstream_example --help
# Run integrated sender/receiver test with data verification (default)
./chunkstream_example both
# Run with custom port
./chunkstream_example both --port 8080
# Run sender only to specific host and port
./chunkstream_example sender --host 192.168.1.100 --port 5555
# Run receiver only on specific port
./chunkstream_example receiver --port 5555| Option | Description | Available Modes | Default |
|---|---|---|---|
--host HOST |
Target IP address | sender only | 127.0.0.1 |
--port PORT |
UDP port number | all modes | 56343 |
--help, -h |
Show help message | all modes | - |
# Local loopback test with data integrity verification
./chunkstream_example both --port 9090- Runs both sender and receiver in same process
- Automatic data integrity verification
- Real-time performance statistics
- Ideal for library testing and benchmarking
# Send to remote receiver
./chunkstream_example sender --host 192.168.1.100 --port 5555- Continuously sends test data frames
- Performance statistics display
- Useful for network testing and load generation
# Receive on specific port
./chunkstream_example receiver --port 5555- Listens for incoming data frames
- Data integrity verification
- Performance monitoring
- Ideal for testing receiver performance
The test application provides comprehensive analysis:
- Real-time Statistics: Live FPS, throughput, and performance metrics
- Data Integrity Verification: Automatic corruption detection and reporting
- Packet Loss Analysis: Drop rate monitoring and statistics
- Latency Measurements: Round-trip time and distribution analysis
- Network Performance: Throughput and efficiency metrics
# Terminal 1: Start receiver
./chunkstream_example receiver --port 8080
# Terminal 2: Start sender to remote host
./chunkstream_example sender --host 192.168.1.100 --port 8080
# Press Enter to stop test and view detailed results# Local performance benchmark
./chunkstream_example both --port 7777
# Cross-network reliability test
./chunkstream_example sender --host 10.0.0.50 --port 6666
# High-port testing (avoiding conflicts)
./chunkstream_example both --port 55555ChunkStream is designed for multi-threaded environments:
- Thread Pool: Automatic work distribution across available CPU cores
- Memory Pools: Thread-safe memory allocation and deallocation
- Atomic Counters: Lock-free statistics tracking
- Mutex Protection: Critical sections properly protected
Ensure UDP traffic is allowed on your chosen ports:
# Linux (iptables)
sudo iptables -A INPUT -p udp --dport 5555 -j ACCEPT
# Windows (PowerShell as Administrator)
New-NetFirewallRule -DisplayName "ChunkStream" -Direction Inbound -Protocol UDP -LocalPort 5555 -Action Allow- Jumbo Frames: Use MTU 9000 for high-speed networks
- Buffer Tuning: Increase system UDP buffer sizes for high-throughput applications
- CPU Affinity: Consider pinning threads to specific CPU cores for consistent performance
-
High Packet Loss
- Reduce MTU size
- Increase buffer sizes
- Check network capacity
-
Memory Issues
- Reduce buffer_size parameter
- Implement proper release() callback handling
- Monitor memory usage with system tools
-
Performance Issues
- Enable compiler optimizations (-O3)
- Use Release build configuration
- Consider network hardware limitations
-
Connection Issues
- Verify firewall settings
- Check port availability with
netstat -an | grep PORT - Ensure correct IP addresses and routing
- Use
bothmode for initial testing and library validation - Test with
sender/receivermodes for network-specific scenarios - Monitor system resources during high-throughput tests
- Use different ports to avoid conflicts with existing services
This project is licensed under the MIT License - see the LICENSE file for details.