rgtp
v3.0.2
Published
Red Giant Transport Protocol - High-performance UDP-based transport protocol
Maintainers
Readme
Red Giant Transport Protocol (RGTP) - Node.js Bindings
High-performance UDP-based transport protocol for Node.js with full JavaScript API.
Key Features:
- Session/Client Architecture - Event-driven file transfer
- Progress Tracking - Real-time transfer monitoring
- Configuration Presets - Optimized for LAN/WAN/mobile
- Cross-platform - Works on Windows, macOS, and Linux
- Native Performance - Built on proven C core implementation
Installation
Quick Install
npm install rgtpPrerequisites
- Node.js 14.0.0 or higher
- npm 6.0.0 or higher
- Build tools (automatically installed on most systems)
The package includes pre-built binaries for major platforms.
Quick Start
Server Side (Expose a File)
const rgtp = require('rgtp');
// Create server session
const session = new rgtp.Session({
port: 9999,
adaptiveMode: true
});
// Listen for events
session.on('exposeStart', (filePath, fileSize) => {
console.log(`Exposing ${filePath} (${fileSize} bytes)`);
});
session.on('progress', (transferred, total) => {
const percent = ((transferred / total) * 100).toFixed(1);
console.log(`Progress: ${percent}%`);
});
session.on('error', (error) => {
console.error('Error:', error.message);
});
// Expose file
await session.exposeFile('large-file.bin');
console.log('File exposed successfully!');
// Get statistics
const stats = await session.getStats();
console.log(`Transferred: ${rgtp.formatBytes(stats.bytesTransferred)}`);
console.log(`Throughput: ${stats.avgThroughputMbps.toFixed(2)} MB/s`);
// Cleanup
session.close();Client Side (Pull a File)
const rgtp = require('rgtp');
// Create client
const client = new rgtp.Client({
timeout: 30000
});
// Listen for events
client.on('pullStart', (host, port, outputPath) => {
console.log(`Downloading from ${host}:${port} to ${outputPath}`);
});
client.on('progress', (transferred, total) => {
const percent = ((transferred / total) * 100).toFixed(1);
console.log(`Download progress: ${percent}%`);
});
client.on('pullComplete', (outputPath) => {
console.log(`Download complete: ${outputPath}`);
});
// Pull file
await client.pullToFile('192.168.1.100', 9999, 'downloaded-file.bin');
console.log('File downloaded successfully!');
// Get statistics
const stats = await client.getStats();
console.log(`Received: ${rgtp.formatBytes(stats.bytesTransferred)}`);
// Cleanup
client.close();Convenience Functions
For simple use cases:
const rgtp = require('rgtp');
// Send a file (one-liner)
const sendStats = await rgtp.sendFile('my-file.bin', { port: 9999 });
// Receive a file (one-liner)
const receiveStats = await rgtp.receiveFile('host', 9999, 'output.bin');Configuration Presets
const rgtp = require('rgtp');
// High-bandwidth LAN
const lanSession = new rgtp.Session(rgtp.createLANConfig());
// Variable bandwidth WAN
const wanClient = new rgtp.Client(rgtp.createWANConfig());
// Mobile/limited bandwidth
const mobileSession = new rgtp.Session(rgtp.createMobileConfig());API Reference
RGTPSession
Constructor:
new rgtp.Session(options)Options:
port- Port to listen on (0 = auto)chunkSize- Chunk size in bytes (default: 1MB)adaptiveMode- Enable adaptive rate control (default: true)timeout- Operation timeout in ms (default: 30000)
Methods:
exposeFile(filePath)- Expose a file for transferwaitComplete()- Wait for all transfers to completegetStats()- Get transfer statisticsclose()- Close the session
Events:
exposeStart- File exposure startedprogress- Transfer progress updateerror- Error occurredclose- Session closed
RGTPClient
Constructor:
new rgtp.Client(options)Options:
timeout- Connection timeout in ms (default: 30000)chunkSize- Preferred chunk size (default: 1MB)adaptiveMode- Enable adaptive mode (default: true)
Methods:
pullToFile(host, port, outputPath)- Pull file from servergetStats()- Get transfer statisticsclose()- Close the client
Events:
pullStart- File download startedprogress- Download progress updatepullComplete- Download completederror- Error occurredclose- Client closed
Examples
Run the included examples:
# Simple transfer demo
npm run example
# Server demo
npm run examples:server
# Client demo
npm run examples:clientPerformance Tips
- Chunk Size: Adjust based on network conditions
- Adaptive Mode: Keep enabled for optimal performance
- Event Handling: Use progress events for real-time feedback
- Error Handling: Always wrap operations in try-catch blocks
License
MIT - See LICENSE file for details.
Contributing
Contributions welcome! Please read CONTRIBUTING.md for guidelines.
Support
For issues and questions, please open an issue on GitHub.
