Meziantou.Framework.MsQuic 1.0.0

Prefix Reserved
dotnet add package Meziantou.Framework.MsQuic --version 1.0.0
                    
NuGet\Install-Package Meziantou.Framework.MsQuic -Version 1.0.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="Meziantou.Framework.MsQuic" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Meziantou.Framework.MsQuic" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Meziantou.Framework.MsQuic" />
                    
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 Meziantou.Framework.MsQuic --version 1.0.0
                    
#r "nuget: Meziantou.Framework.MsQuic, 1.0.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 Meziantou.Framework.MsQuic@1.0.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=Meziantou.Framework.MsQuic&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Meziantou.Framework.MsQuic&version=1.0.0
                    
Install as a Cake Tool

Meziantou.Framework.MsQuic

A .NET binding of MsQuic, the QUIC implementation that System.Net.Quic uses, with the features System.Net.Quic does not expose:

  • Datagrams (RFC 9221): unreliable messages on the connection, with the maximum size MsQuic reports as path MTU discovery progresses
  • Stream priorities: the data of the streams with a higher priority is sent first
  • Connection statistics: round-trip time, bytes and packets sent and received, losses, congestion window
  • Congestion control: CUBIC or BBR
  • Stream limits: open a stream without waiting when the peer does not allow one more

The API follows the shape of System.Net.Quic: MsQuicListener, MsQuicConnection and MsQuicStream (a Stream).

Usage

// A self-signed certificate for the server
using var key = ECDsa.Create(ECCurve.NamedCurves.nistP256);
var request = new CertificateRequest("CN=localhost", key, HashAlgorithmName.SHA256);
using var ephemeralCertificate = request.CreateSelfSigned(DateTimeOffset.UtcNow.AddMinutes(-5), DateTimeOffset.UtcNow.AddDays(10));
using var certificate = X509CertificateLoader.LoadPkcs12(ephemeralCertificate.Export(X509ContentType.Pkcs12), password: null, X509KeyStorageFlags.Exportable);
var protocol = new SslApplicationProtocol("example");

// The server accepts datagrams and echoes them
var listenerOptions = new MsQuicListenerOptions
{
    ListenEndPoint = new IPEndPoint(IPAddress.Loopback, 0),
    ConnectionOptionsCallback = (clientHello, cancellationToken) => ValueTask.FromResult(new MsQuicServerConnectionOptions
    {
        EnableDatagrams = true,
        ServerAuthenticationOptions = new SslServerAuthenticationOptions
        {
            ServerCertificate = certificate,
            ApplicationProtocols = [protocol],
        },
    }),
};
listenerOptions.ApplicationProtocols.Add(protocol);
await using var listener = await MsQuicListener.ListenAsync(listenerOptions);

// The client trusts the certificate of the server by its hash
var serverCertificateHash = certificate.GetCertHash(HashAlgorithmName.SHA256);
var connectTask = MsQuicConnection.ConnectAsync(new MsQuicClientConnectionOptions
{
    RemoteEndPoint = listener.LocalEndPoint,
    EnableDatagrams = true,
    ClientAuthenticationOptions = new SslClientAuthenticationOptions
    {
        ApplicationProtocols = [protocol],
        TargetHost = "localhost",
        RemoteCertificateValidationCallback = (sender, serverCertificate, chain, errors) =>
            serverCertificate is not null && serverCertificate.GetCertHash(HashAlgorithmName.SHA256).AsSpan().SequenceEqual(serverCertificateHash),
    },
});

await using var serverConnection = await listener.AcceptConnectionAsync();
await using var client = await connectTask;

// Datagrams: unreliable, unordered, at most MaxDatagramSendSize bytes
await client.SendDatagramAsync("ping"u8.ToArray());
var datagram = await serverConnection.ReceiveDatagramAsync();
await serverConnection.SendDatagramAsync(datagram);
var echo = await client.ReceiveDatagramAsync();
Assert.Equal("ping", Encoding.UTF8.GetString(echo));

// Streams: reliable and ordered
await using var stream = await client.OpenOutboundStreamAsync(MsQuicStreamType.Bidirectional);
await stream.WriteAsync("hello"u8.ToArray(), completeWrites: true);
await using var serverStream = await serverConnection.AcceptInboundStreamAsync();
var received = new byte[5];
await serverStream.ReadExactlyAsync(received);
Assert.Equal("hello", Encoding.UTF8.GetString(received));

await client.CloseAsync(errorCode: 0);

Requirements

  • On Windows, MsQuic ships with .NET.
  • On Linux, install the libmsquic package from the Microsoft package repository.
  • On macOS, install it with brew install libmsquic.
  • The process must be 64-bit. MsQuicLibrary.IsSupported and MsQuicLibrary.NotSupportedReason tell whether MsQuic is available.
  • On Linux and macOS, the private key of the server certificate must be exportable: MsQuic loads it from a PKCS #12 export.
Product 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.  net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net11.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Meziantou.Framework.MsQuic:

Package Downloads
Meziantou.Framework.WebTransport

A WebTransport over HTTP/3 client and server, with streams and datagrams, built on MsQuic

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 61 11/26/2026