TechTeaStudio.Protocols.Hyperion
0.1.1
dotnet add package TechTeaStudio.Protocols.Hyperion --version 0.1.1
NuGet\Install-Package TechTeaStudio.Protocols.Hyperion -Version 0.1.1
<PackageReference Include="TechTeaStudio.Protocols.Hyperion" Version="0.1.1" />
<PackageVersion Include="TechTeaStudio.Protocols.Hyperion" Version="0.1.1" />
<PackageReference Include="TechTeaStudio.Protocols.Hyperion" />
paket add TechTeaStudio.Protocols.Hyperion --version 0.1.1
#r "nuget: TechTeaStudio.Protocols.Hyperion, 0.1.1"
#:package TechTeaStudio.Protocols.Hyperion@0.1.1
#addin nuget:?package=TechTeaStudio.Protocols.Hyperion&version=0.1.1
#tool nuget:?package=TechTeaStudio.Protocols.Hyperion&version=0.1.1
๐ HyperionProtocol
A high-performance, chunked TCP messaging protocol for .NET ๐
๐ Table of Contents
- Features
- Quick Start
- Installation
- Usage
- Architecture
- Testing
- Performance
- API Reference
- Contributing
- License
โจ Features
- ๐ฅ High Performance: Efficient chunked data transmission
- ๐ฆ Large Data Support: Seamlessly handles files up to several GB
- ๐ Chunked Protocol: Automatic splitting of large messages into manageable chunks
- ๐ก๏ธ Error Handling: Robust error detection and recovery
- โก Async/Await: Fully asynchronous API with cancellation support
- ๐งช Well Tested: Comprehensive test suite with NUnit
- ๐ง Extensible: Pluggable serialization system
- ๐ Packet Integrity: Each message has unique ID and chunk validation
๐ Quick Start
Server Example
using TechTeaStudio.Protocols.Hyperion;
var listener = new TcpListener(IPAddress.Any, 8080);
listener.Start();
while (true)
{
var client = await listener.AcceptTcpClientAsync();
_ = HandleClientAsync(client);
}
async Task HandleClientAsync(TcpClient client)
{
using var stream = client.GetStream();
var protocol = new HyperionProtocol(new JsonSerializer());
var message = await protocol.ReceiveAsync<string>(stream);
Console.WriteLine($"๐จ Received: {message}");
await protocol.SendAsync($"Echo: {message}", stream);
}
Client Example
using var client = new TcpClient();
await client.ConnectAsync("localhost", 8080);
using var stream = client.GetStream();
var protocol = new HyperionProtocol(new JsonSerializer());
await protocol.SendAsync("Hello HyperionProtocol! ๐", stream);
var response = await protocol.ReceiveAsync<string>(stream);
Console.WriteLine($"๐ฌ Server replied: {response}");
๐ฅ Installation
Option 1: Clone and Build
git clone https://github.com/yourusername/HyperionProtocol.git
cd HyperionProtocol
dotnet build
Option 2: Add as Project Reference
- Copy the
TechTeaStudio.Protocols.Hyperion
folder to your solution - Add project reference:
<ProjectReference Include="..\TechTeaStudio.Protocols.Hyperion\TechTeaStudio.Protocols.Hyperion.csproj" />
๐ ๏ธ Usage
Basic Setup
// 1๏ธโฃ Create a serializer
var serializer = new DefaultSerializer(); // or implement ISerializer
// 2๏ธโฃ Create protocol instance
var protocol = new HyperionProtocol(serializer);
// 3๏ธโฃ Send/Receive data
await protocol.SendAsync(myData, networkStream);
var receivedData = await protocol.ReceiveAsync<MyType>(networkStream);
Sending Large Files ๐
var fileBytes = await File.ReadAllBytesAsync("largefile.zip");
await protocol.SendAsync(fileBytes, stream);
// File is automatically chunked into 1MB pieces
// and reassembled on the receiving end! โจ
Custom Serialization
public class MyCustomSerializer : ISerializer
{
public byte[] Serialize<T>(T obj)
{
// Your custom serialization logic
return MessagePack.Serialize(obj);
}
public T Deserialize<T>(byte[] data)
{
// Your custom deserialization logic
return MessagePack.Deserialize<T>(data);
}
}
Error Handling ๐ก๏ธ
try
{
await protocol.SendAsync(data, stream, cancellationToken);
}
catch (HyperionProtocolException ex)
{
Console.WriteLine($"๐จ Protocol error: {ex.Message}");
}
catch (OperationCanceledException)
{
Console.WriteLine("โน๏ธ Operation was cancelled");
}
๐๏ธ Architecture
Protocol Structure
๐ฆ Packet Structure:
โโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโ
โ Header Length โ JSON Header โ Payload Data โ
โ (4 bytes) โ (variable) โ (โค 1MB) โ
โโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโ
Header Format
{
"Magic": "TTS",
"PacketId": "guid-here",
"ChunkNumber": 0,
"TotalChunks": 5,
"DataLength": 1048576,
"Flags": 0
}
Chunk Flow ๐
Large Message (5MB)
โ
Chunking ๐ฆ
โ
โโโโโโโโโโโฌโโโโโโโโโโฌโโโโโโโโโโฌโโโโโโโโโโฌโโโโโโโโโโ
โ Chunk 0 โ Chunk 1 โ Chunk 2 โ Chunk 3 โ Chunk 4 โ
โ 1MB โ 1MB โ 1MB โ 1MB โ 1MB โ
โโโโโโโโโโโดโโโโโโโโโโดโโโโโโโโโโดโโโโโโโโโโดโโโโโโโโโโ
โ
Network Transfer ๐
โ
Reassembly ๐ง
โ
Complete Message โ
๐งช Testing
Run All Tests
cd TechTeaStudio.Protocols.Hyperion.Tests
dotnet test
Run Specific Test Category
# Performance tests
dotnet test --filter "Category=Performance"
# Basic functionality
dotnet test --filter "SendReceive"
# Error handling
dotnet test --filter "Exception"
Test Console Application
cd ConsoleApp
dotnet run
Expected output:
๐ฏ Starting Hyperion Protocol minimal test...
๐ก Server listening on port 6000...
๐ค [Client] Sending: Hello HyperionProtocol!
๐จ [Server] Received: Hello HyperionProtocol!
๐ฌ [Client] Received: Echo: Hello HyperionProtocol!
โ
Test PASSED
โก Performance
Benchmarks ๐
Test Scenario | Data Size | Time | Throughput |
---|---|---|---|
Small Message | 1KB | ~1ms | ~1MB/s |
Medium File | 1MB | ~10ms | ~100MB/s |
Large File | 100MB | ~500ms | ~200MB/s |
Huge File | 1GB | ~3-5s | ~200-300MB/s |
Memory Usage ๐พ
- Chunk Size: 1MB (configurable)
- Memory Footprint: ~2-3MB per active connection
- GC Pressure: Minimal due to efficient buffering
๐ API Reference
HyperionProtocol Class
Constructor
public HyperionProtocol(ISerializer serializer)
Methods
SendAsync
public async Task SendAsync<T>(T message, NetworkStream stream, CancellationToken ct = default)
Sends a message through the network stream.
Parameters:
message
: Object to sendstream
: Network streamct
: Cancellation token
ReceiveAsync
public async Task<T> ReceiveAsync<T>(NetworkStream stream, CancellationToken ct = default)
Receives a message from the network stream.
Returns: Deserialized object of type T
ISerializer Interface
public interface ISerializer
{
byte[] Serialize<T>(T obj);
T Deserialize<T>(byte[] data);
}
HyperionProtocolException
Custom exception thrown when protocol-level errors occur.
public class HyperionProtocolException : Exception
{
public HyperionProtocolException(string message);
public HyperionProtocolException(string message, Exception innerException);
}
๐๏ธ Project Structure
HyperionProtocol/
โโโ ๐ src/
โ โโโ ๐ TechTeaStudio.Protocols.Hyperion/ # ๐ฏ Main library
โ โ โโโ ๐ HyperionProtocol.cs # ๐ Core protocol
โ โ โโโ ๐ PacketHeader.cs # ๐ฆ Packet structure
โ โ โโโ ๐ ISerializer.cs # ๐ Serialization interface
โ โ โโโ ๐ HyperionProtocolException.cs # ๐จ Custom exceptions
โ โโโ ๐ ConsoleApp/ # ๐ฅ๏ธ Demo application
โ โโโ ๐ Program.cs # ๐ฎ Demo code
โ โโโ ๐ DefaultSerializer.cs # ๐ Basic serializer
โโโ ๐ tests/
โ โโโ ๐ TechTeaStudio.Protocols.Hyperion.Tests/ # ๐งช Unit tests
โ โโโ ๐ HyperionProtocolTests.cs # ๐ Protocol tests
โ โโโ ๐ DefaultSerializerTests.cs # ๐ Serializer tests
โโโ ๐ README.md # ๐ This file
โโโ ๐ LICENSE # โ๏ธ MIT License
๐ง Configuration
Chunk Size
// Default: 1MB (1024 * 1024 bytes)
private const int ChunkSize = 1024 * 1024;
Header Limits
// Maximum header size: 64KB
private const int MaxHeaderLength = 64 * 1024;
Timeouts โฐ
client.ReceiveTimeout = 30000; // 30 seconds
client.SendTimeout = 30000; // 30 seconds
๐ค Contributing
We welcome contributions! ๐
- ๐ด Fork the repository
- ๐ฟ Create your feature branch (
git checkout -b feature/amazing-feature
) - ๐พ Commit your changes (
git commit -m 'Add some amazing feature'
) - ๐ค Push to the branch (
git push origin feature/amazing-feature
) - ๐ Open a Pull Request
Development Setup ๐จโ๐ป
# Clone repo
git clone https://github.com/yourusername/HyperionProtocol.git
cd HyperionProtocol
# Restore packages
dotnet restore
# Build solution
dotnet build
# Run tests
dotnet test
# Run demo
cd src/ConsoleApp && dotnet run
๐ Troubleshooting
Common Issues
๐จ "Stream ended while reading header length"
- Ensure server doesn't close connection before client reads response
- Add proper
FlushAsync()
calls - Check network connectivity
๐ Slow performance with large files
- Increase network buffer sizes
- Consider compression for text data
- Monitor memory usage
โ Serialization errors
- Ensure both ends use compatible serializers
- Handle null values properly
- Check data type compatibility
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Built with โค๏ธ using .NET 8-9
- Special thanks to the RonaldRyan
Made by TechTeaStudio
โญ Don't forget to star the repository if you find it useful!
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Added SmartVersion of the protocol with reduced overhead.