Beskar.Networking.Transports.Tcp.Tests
1.1.1
dotnet add package Beskar.Networking.Transports.Tcp.Tests --version 1.1.1
NuGet\Install-Package Beskar.Networking.Transports.Tcp.Tests -Version 1.1.1
<PackageReference Include="Beskar.Networking.Transports.Tcp.Tests" Version="1.1.1" />
<PackageVersion Include="Beskar.Networking.Transports.Tcp.Tests" Version="1.1.1" />
<PackageReference Include="Beskar.Networking.Transports.Tcp.Tests" />
paket add Beskar.Networking.Transports.Tcp.Tests --version 1.1.1
#r "nuget: Beskar.Networking.Transports.Tcp.Tests, 1.1.1"
#:package Beskar.Networking.Transports.Tcp.Tests@1.1.1
#addin nuget:?package=Beskar.Networking.Transports.Tcp.Tests&version=1.1.1
#tool nuget:?package=Beskar.Networking.Transports.Tcp.Tests&version=1.1.1
<h1> <p align="center"> <img src="https://github.com/MarvinDrude/Beskar.Networking/blob/master/Resources/banner.png" alt="Logo" width="256" /> <br /> Beskar.Networking </p> </h1> <p align="center"> Fast, <code>.NET</code> native, high-performance, low-allocation networking library.<br/> Built for modern <code>.NET</code> using <code>C#</code> includes TCP, WebSockets, QUIC, and MQTT.<br/> No external runtime dependencies besides <b>Beskar</b>.<br/><br/> <a href="#about">About</a> · <a href="#examples">Examples</a> · <a href="#documenation">Documentation</a> · <a href="#performance-benchmarks">Performance</a> · <a href="#key-aspects">Key Aspects</a> </p> <br/>
<br/>
About
Main reasons for why you should consider using Beskar.Networking for your next Networking or MQTT use case:
- Made with passion and love for the craft.
- Built for modern
.NETusingC#and designed to be highly performant, low-allocation, and easy to use. - Purposefully designed to be lightweight and flexible.
- Performance-first approach with 100,000 - 10,800,000 messages/packets per second. (Depending on various factors)
- Many simple or more advanced example projects demonstrating how to use
Beskar.Networkingacross various transports. - Various Unit Tests to verify functionality and performance.
- Active development and steady progress towards a full feature set.
- MQTT V3 and V5 support. (Server and Client) – Over any transport supported by Beskar.
- No external runtime dependencies besides .NET and Beskar.
API Overview
Beskar.Networking offers different levels of abstraction depending on your application needs:
Low-Level Transports
The core library features protocol-agnostic, low-level interfaces:
INetworkListener- The Server listener that accepts incoming connections and manages sessions.INetworkClient- The client that initiates connections and manages sessions.INetworkSession- Represents a single connection between a client and server.INetworkStream- Provides transport-agnostic handling (supporting TCP, WebSockets, or QUIC).
These interfaces provide transport-agnostic handling (supporting TCP, WebSockets, or QUIC). Because they are low-level, you are responsible for managing execution tasks yourself, such as starting your own accept loops, launching read/write tasks, and supervising session lifecycles.
Client Transport Optimization (Low-Level APIs)
When instantiating TcpNetworkClient, WsNetworkClient, or QuicNetworkClient directly with custom options (TcpTransportOptions, WsTransportOptions, QuicTransportOptions), the default IoQueueCount is optimized for servers and defaults to Math.Min(Environment.ProcessorCount, 24).
For client-side applications, you should explicitly configure the option's IoQueueCount (e.g. options.StreamOptions.IoQueueCount = 1 and options.SocketOptions.IoQueueCount = 1) to 1. Since a client only manages a single connection, this prevents allocating unnecessary idle memory pools and thread queues, drastically reducing the unmanaged and pinned memory footprint.
For more details, see the Basics Documentation.
High-Level Managed APIs
For protocols like MQTT, Beskar.Networking provides fully managed implementations:
- Fully Managed Broker & Client: Pre-built wrappers that manage the connection, session, and stream states automatically.
- Event-Driven: Fully event-driven design with convenient events to react to incoming messages, client connections, and subscription actions, eliminating the need to write custom accept loops or pipeline plumbing.
In the future, additional managed APIs for other application protocols will be added here.
NuGet packages overview
Examples
We provide both basic and advanced example projects demonstrating how to use Beskar.Networking across various transports:
All examples: Root Folder
- Simple Ping-Pong Message (Bare-metal): Demonstrates low-level server listener binding, client connection, and raw bidirectional message exchange using length-prefixed framing over
System.IO.Pipelinesusing TCP. - Advanced Multi-Transport Chat Application: A complete chat application consisting of:
- Common: Reusable packet serialization and custom packet framing utilities.
- Server: Integrates a unified
ChatServerBuilderto listen and accept chat sessions concurrently on TCP (9000), WebSockets (11000), and QUIC (12000). - Client: An interactive console application allowing users to connect via their choice of protocol (TCP/WS/QUIC), receive recent chat history, and chat in real-time under a random username.
- MQTT Managed Examples: A set of projects demonstrating the high-level managed MQTT APIs:
- Simple Publish-Subscribe: A complete pub-sub flow showing how to spin up an MQTT broker, connect a sensor client (publisher) and dashboard client (subscriber) over TCP using MQTT v5.0.
- Generated Pub-Sub (Source Generator): Showcases how to use the high-performance MQTT Topic Source Generator to define compile-time validated topics and perform zero-allocation publishing using the generated
byte[]format overloads. - Quality of Service (QoS) Levels: Demonstrates publishing and subscribing messages with different QoS levels (QoS 0: At Most Once, QoS 1: At Least Once, QoS 2: Exactly Once) using wildcard topic filters.
- Authentication (v3 & v5 Challenges): Highlights both simple username/password validation for MQTT v3.1.1 and advanced challenge-response authentication for MQTT v5.0.
- Client Reconnection & Event Handling: Shows how to register connection status events and implement custom auto-reconnection loops when connections are unexpectedly lost.
Documenation
You can find detailed documentation for Beskar.Networking here.
Or you can find examples directly here.
Performance Benchmarks
Engineered from the ground up for maximum throughput and minimum allocation overhead.
[!NOTE]
Computer Specs:<br/> CPU: AMD Ryzen 9 7950X3D, Memory: 64 GB DDR5Method: Payload does not include protocol, Local Loopback Benchmark<br /> Note: Benchmarks are subject to change as the library evolves.
| Transport / Protocol | Clients | Payload Size | Throughput | Bandwidth |
|---|---|---|---|---|
| TCP (No TLS) | 20 | 128 bytes | 10,805,651 packets/s | 1,319.05 MB/s |
| TCP (No TLS) | 20 | 512 bytes | 7,355,303 packets/s | 3,591.46 MB/s |
| WebSockets (WS) (No TLS) | 20 | 128 bytes | 10,784,817 packets/s | 1,316.51 MB/s |
| WebSockets (WS) (No TLS) | 20 | 512 bytes | 6,968,596 packets/s | 3,402.63 MB/s |
| QUIC | 20 | 128 bytes | 3,503,372 packets/s | 427.66 MB/s |
| QUIC | 20 | 512 bytes | 954,711 packets/s | 466.17 MB/s |
| MQTT (TCP - No TLS) | 20 | 128 bytes | 918,794.17 msg/s | 112.16 MB/s |
| MQTT (TCP - No TLS) | 20 | 512 bytes | 674,086.45 msg/s | 329.14 MB/s |
Key Aspects
Beskar.Networking is a high-performance, low-allocation networking library built for modern .NET 10 using C#.
It provides a unified, pipe-based interface abstraction (INetworkListener, INetworkClient, INetworkSession, INetworkStream)
for building extremely fast network applications across multiple transport protocols.
- Unified Abstractions: Write your network layer once and swap between TCP, WebSockets, or QUIC etc. dynamically.
- Modern .NET 10 Stack: Heavily leverages
System.IO.Pipelines(decoupling IO thread queues from application processing),Span<T>,ReadOnlySpan<T>, and direct memory pooling to achieve zero/near-zero allocations. - TLS/SSL Encryption: Full native SSL/TLS wrapping for TCP and WebSocket transports out of the box.
- Non-blocking IO Queueing: Highly-optimized custom IO queues (like
TcpIoQueueRegistry/TcpIoQueue) to handle asynchronous reading and writing concurrently. - Full MQTT:
- Other Features: Additional features and capabilities that make this library unique and valuable.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- Beskar.Memory (>= 1.7.1)
- Beskar.Networking.Transports.Quic (>= 1.1.1)
- Beskar.Networking.Transports.Tcp (>= 1.1.1)
- TUnit (>= 1.61.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.