Beskar.Mqtt.Server
3.0.1
dotnet add package Beskar.Mqtt.Server --version 3.0.1
NuGet\Install-Package Beskar.Mqtt.Server -Version 3.0.1
<PackageReference Include="Beskar.Mqtt.Server" Version="3.0.1" />
<PackageVersion Include="Beskar.Mqtt.Server" Version="3.0.1" />
<PackageReference Include="Beskar.Mqtt.Server" />
paket add Beskar.Mqtt.Server --version 3.0.1
#r "nuget: Beskar.Mqtt.Server, 3.0.1"
#:package Beskar.Mqtt.Server@3.0.1
#addin nuget:?package=Beskar.Mqtt.Server&version=3.0.1
#tool nuget:?package=Beskar.Mqtt.Server&version=3.0.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>C#</code> includes TCP, WebSockets, QUIC, UDP, UDS, Named Pipes, Memory, 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.
- Native OpenTelemetry and
System.Diagnostics.Metricstelemetry support across all transports, resilient protocol, and MQTT. See Telemetry Meters. - MQTT V3 and V5 support. (Server and Client) – Over any transport supported by Beskar.
- No external runtime dependencies besides .NET and Beskar.
NuGet packages overview
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, QUIC, UDP, UDS, Named Pipes, or Memory).
These interfaces provide transport-agnostic handling (supporting TCP, WebSockets, QUIC, UDP, UDS, Named Pipes, or Memory). 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, QuicNetworkClient, UdsNetworkClient, or NamedPipeNetworkClient directly with custom options (TcpTransportOptions, WsTransportOptions, QuicTransportOptions, UdsTransportOptions, NamedPipeTransportOptions), 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, or connection-resilient networking, Beskar.Networking provides fully managed implementations:
- Fully Managed Broker & Client (MQTT): Pre-built wrappers that manage the connection, session, and stream states automatically.
- Resilient Client & Server: Connection-resilient managed wrappers (
ResilientClient<TFrame>andResilientServer<TFrame>) that handle transient disconnect supervision, automatic pings/pongs (keep-alive), protocol control handshakes, custom challenge-response authentication, and pluggable framing protocol generation. - Event-Driven: Fully event-driven design with convenient events to react to incoming messages, client connections, and status updates, eliminating the need to write custom accept loops or pipeline plumbing.
For more details, see the Resilient Documentation and Mqtt Documentation.
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.
- Disconnection Safety & Persistence: Demonstrates persistent sessions, server-side JSON serialization/restoration of retained messages, and client-side offline queuing (FIFO and Last Message Buffering) with crash safety.
- Last Will and Testament (LWT): Shows how to configure client Will messages and verify that the server automatically delivers them upon ungraceful connection loss while ignoring them on graceful disconnects.
- User Properties (Metadata): Demonstrates how to send and receive custom metadata headers (like trace context spans) using MQTT v5.0 User Properties.
- Topic Aliases (Bandwidth Optimization): Illustrates how client and server negotiate and employ Topic Aliases to dramatically decrease packet sizes by substituting long topic paths with short integer codes.
- Resilient Managed Examples: A set of projects demonstrating the high-level connection-resilient server and client wrappers:
- Resilient Chat Application: A complete chat application using the resilient wrappers with default
BeskarPacketframing and automated JSON serialization:- Common: Contains shared message payloads and a JSON
ChatSerializerimplementingIResilientSerializer. - Server: Integrates
ResilientServer<BeskarPacket>to accept, track, and broadcast chat messages over TCP port 9000. - Client: Interactive chat client using
ResilientClient<BeskarPacket>that reconnects and re-authenticates/joins automatically when connection is lost.
- Common: Contains shared message payloads and a JSON
- Simple Ping-Pong: Demonstrates basic ping-pong message exchange using
ResilientServerandResilientClientwith default framing over TCP port 9001. - Authentication Challenge-Response: Highlights pre-handshake HMAC-SHA256 signature challenge-response authentication, showing both success and server-denial test cases on TCP port 9002.
- Resilient Chat Application: A complete chat application using the resilient wrappers with default
- Telemetry & OpenTelemetry Console: Demonstrates how to subscribe to all native telemetry meters using
MeterListeneror OpenTelemetry exporters, showing real-time event streaming and a live metrics summary dashboard as operations occur.
Documentation
You can find detailed documentation for Beskar.Networking here.
- Telemetry Meters Reference: Detailed reference of all OpenTelemetry and
System.Diagnostics.Metricsmeters, instruments, types, units, and descriptions across MQTT, Resilient, and Transports.
Or you can find examples directly here.
Performance Benchmarks
<a href="https://www.http-arena.com/#scope=ws&type=experimental,flagship"> <img src="https://cdn.jsdelivr.net/gh/MDA2AV/httparena-badge/wordmark.svg" alt="Benchmarked by HttpArena" height="44"> </a>
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 |
| UDP | 20 | 128 bytes | 3,480,517 packets/s | 424.87 MB/s |
| UDP | 20 | 512 bytes | 801,432 packets/s | 391.32 MB/s |
| Unix Domain Sockets (UDS) | 20 | 128 bytes | 11,993,784 packets/s | 1,464.08 MB/s |
| Unix Domain Sockets (UDS) | 20 | 512 bytes | 9,487,101 packets/s | 4,632.37 MB/s |
| Named Pipes | 20 | 128 bytes | 12,777,198 packets/s | 1,559.72 MB/s |
| Named Pipes | 20 | 512 bytes | 5,739,487 packets/s | 2,802.48 MB/s |
| Memory | 20 | 128 bytes | 8,388,522 packets/s | 1,023.99 MB/s |
| Memory | 20 | 512 bytes | 7,728,970 packets/s | 3,773.91 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, QUIC, UDP, UDS, Named Pipes, or Memory 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. - Native OpenTelemetry & Metrics: Built-in
System.Diagnostics.Metricsmeters and instruments tracking live active connections, streams, byte throughput, MQTT broker sessions/retries/retained messages, and resilient RTT/reconnections. See Telemetry Meters Reference. - Full MQTT: Complete MQTT v3.1.1 and v5.0 server broker and client support over any transport.
| 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.3)
- Beskar.Memory.Code.EnumGenerator (>= 1.7.3)
- Beskar.Mqtt.Client (>= 3.0.1)
- Beskar.Mqtt.Common (>= 3.0.1)
- Beskar.Mqtt.Protocol (>= 3.0.1)
NuGet packages (9)
Showing the top 5 NuGet packages that depend on Beskar.Mqtt.Server:
| Package | Downloads |
|---|---|
|
Beskar.Mqtt.Example.QosLevels
Package Description |
|
|
Beskar.Mqtt.Example.SimplePubSub
Package Description |
|
|
Beskar.Mqtt.ChaosSimulator
Package Description |
|
|
Beskar.Mqtt.Common.Tests
Package Description |
|
|
Beskar.Mqtt.Example.Reconnection
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.0.1 | 0 | 8/7/2026 |
| 3.0.0 | 0 | 8/7/2026 |
| 2.1.6 | 33 | 8/6/2026 |
| 2.1.5 | 34 | 8/6/2026 |
| 2.1.4 | 36 | 8/6/2026 |
| 2.1.3 | 69 | 8/5/2026 |
| 2.1.2 | 106 | 7/25/2026 |
| 2.1.1 | 102 | 7/25/2026 |
| 2.1.0 | 111 | 7/25/2026 |
| 2.0.1 | 105 | 7/25/2026 |
| 2.0.0 | 107 | 7/25/2026 |
| 1.2.1 | 98 | 7/20/2026 |
| 1.2.0 | 101 | 7/20/2026 |
| 1.1.4 | 92 | 7/20/2026 |
| 1.1.3 | 97 | 7/19/2026 |
| 1.1.2 | 110 | 7/19/2026 |
| 1.1.1 | 178 | 7/19/2026 |
| 1.1.0 | 185 | 7/19/2026 |
| 1.0.1 | 180 | 7/19/2026 |