Base protocol for Hyperion Omni Client.
$ dotnet add package TechTeaStudio.Protocols.HyperionA high-performance, chunked TCP messaging protocol for .NET 🌟
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);
}
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}");
git clone https://github.com/yourusername/HyperionProtocol.git
cd HyperionProtocol
dotnet build
TechTeaStudio.Protocols.Hyperion folder to your solution<ProjectReference Include="..\TechTeaStudio.Protocols.Hyperion\TechTeaStudio.Protocols.Hyperion.csproj" />
// 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);
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! ✨
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);
}
}
try
{
await protocol.SendAsync(data, stream, cancellationToken);
}
catch (HyperionProtocolException ex)
{
Console.WriteLine($"🚨 Protocol error: {ex.Message}");
}
catch (OperationCanceledException)
{
Console.WriteLine("⏹️ Operation was cancelled");
}
📦 Packet Structure:
┌─────────────────┬─────────────────┬─────────────────┐
│ Header Length │ JSON Header │ Payload Data │
│ (4 bytes) │ (variable) │ (≤ 1MB) │
└─────────────────┴─────────────────┴─────────────────┘
{
"Magic": "TTS",
"PacketId": "guid-here",
"ChunkNumber": 0,
"TotalChunks": 5,
"DataLength": 1048576,
"Flags": 0
}
Large Message (5MB)
↓
Chunking 📦
↓
┌─────────┬─────────┬─────────┬─────────┬─────────┐
│ Chunk 0 │ Chunk 1 │ Chunk 2 │ Chunk 3 │ Chunk 4 │
│ 1MB │ 1MB │ 1MB │ 1MB │ 1MB │
└─────────┴─────────┴─────────┴─────────┴─────────┘
↓
Network Transfer 🌐
↓
Reassembly 🔧
↓
Complete Message ✅
cd TechTeaStudio.Protocols.Hyperion.Tests
dotnet test
# Performance tests
dotnet test --filter "Category=Performance"
# Basic functionality
dotnet test --filter "SendReceive"
# Error handling
dotnet test --filter "Exception"
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
| 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 |
public HyperionProtocol(ISerializer serializer)
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 tokenpublic async Task<T> ReceiveAsync<T>(NetworkStream stream, CancellationToken ct = default)
Receives a message from the network stream.
Returns: Deserialized object of type T
public interface ISerializer
{
byte[] Serialize<T>(T obj);
T Deserialize<T>(byte[] data);
}
Custom exception thrown when protocol-level errors occur.
public class HyperionProtocolException : Exception
{
public HyperionProtocolException(string message);
public HyperionProtocolException(string message, Exception innerException);
}
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
// Default: 1MB (1024 * 1024 bytes)
private const int ChunkSize = 1024 * 1024;
// Maximum header size: 64KB
private const int MaxHeaderLength = 64 * 1024;
client.ReceiveTimeout = 30000; // 30 seconds
client.SendTimeout = 30000; // 30 seconds
We welcome contributions! 🎉
git checkout -b feature/amazing-feature)git commit -m 'Add some amazing feature')git push origin feature/amazing-feature)# 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
🚨 "Stream ended while reading header length"
FlushAsync() calls🐌 Slow performance with large files
❌ Serialization errors
This project is licensed under the MIT License - see the LICENSE file for details.
Made by TechTeaStudio
⭐ Don't forget to star the repository if you find it useful!