TechTeaStudio.Protocols.Hyperion 0.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package TechTeaStudio.Protocols.Hyperion --version 0.1.0
                    
NuGet\Install-Package TechTeaStudio.Protocols.Hyperion -Version 0.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TechTeaStudio.Protocols.Hyperion" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TechTeaStudio.Protocols.Hyperion" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="TechTeaStudio.Protocols.Hyperion" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TechTeaStudio.Protocols.Hyperion --version 0.1.0
                    
#r "nuget: TechTeaStudio.Protocols.Hyperion, 0.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package TechTeaStudio.Protocols.Hyperion@0.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TechTeaStudio.Protocols.Hyperion&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=TechTeaStudio.Protocols.Hyperion&version=0.1.0
                    
Install as a Cake Tool

HyperionProtocol

๐Ÿš€ HyperionProtocol

A high-performance, chunked TCP messaging protocol for .NET ๐ŸŒŸ

.NET 8 .NET 9 License NUnit Tests

๐Ÿ“‹ Table of Contents

โœจ 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

  1. Copy the TechTeaStudio.Protocols.Hyperion folder to your solution
  2. 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 send
  • stream: Network stream
  • ct: 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! ๐ŸŽ‰

  1. ๐Ÿด Fork the repository
  2. ๐ŸŒฟ Create your feature branch (git checkout -b feature/amazing-feature)
  3. ๐Ÿ’พ Commit your changes (git commit -m 'Add some amazing feature')
  4. ๐Ÿ“ค Push to the branch (git push origin feature/amazing-feature)
  5. ๐Ÿ”„ 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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.

Version Downloads Last Updated
0.1.1 132 9/2/2025
0.1.0 137 8/31/2025

First release.