MsQuicConnection Class
A QUIC connection: its streams and its datagrams (RFC 9221).
public sealed class MsQuicConnection : IAsyncDisposableRemarks
Create a client connection with MsQuicConnection.ConnectAsync, or accept one with MsQuicListener.AcceptConnectionAsync. Dispose the connection to close it: disposing closes it with MsQuicConnectionOptions.DefaultCloseErrorCode unless MsQuicConnection.CloseAsync closed it.
- Implements
Properties
| Name | Description |
|---|---|
| Closed | Gets a task that completes when the connection is closed, with the exception that describes why: an exception whose MsQuicException.Error is MsQuicError.ConnectionAborted when the peer closed it, MsQuicError.OperationAborted when it was closed locally... |
| IsDatagramSendEnabled | Gets a value indicating whether datagrams can be sent: both peers enabled them and the connection is established. |
| IsSupported | Gets a value indicating whether MsQuic is available, see MsQuicLibrary. |
| LocalEndPoint | Gets the local address of the connection. |
| MaxDatagramSendSize | Gets the maximum size of a datagram payload. It can grow during the connection, as path MTU discovery finds a larger MTU. |
| NegotiatedApplicationProtocol | Gets the application protocol (ALPN) negotiated during the handshake. |
| RemoteCertificate | Gets the certificate of the server, for a client connection. |
| RemoteEndPoint | Gets the address of the peer. |
| TargetHostName | Gets the server name: the target host of a client connection, the server name indication (SNI) the client sent for a server connection. |
Closed
MsQuicConnection.csGets a task that completes when the connection is closed, with the exception that describes why: an exception whose MsQuicException.Error is MsQuicError.ConnectionAborted when the peer closed it, MsQuicError.OperationAborted when it was closed locally...
public Task<MsQuicException> Closed { get; }Property value
IsDatagramSendEnabled
MsQuicConnection.csIsSupported
MsQuicConnection.csGets a value indicating whether MsQuic is available, see MsQuicLibrary.
public static bool IsSupported { get; }Property value
LocalEndPoint
MsQuicConnection.csMaxDatagramSendSize
MsQuicConnection.csNegotiatedApplicationProtocol
MsQuicConnection.csGets the application protocol (ALPN) negotiated during the handshake.
public SslApplicationProtocol NegotiatedApplicationProtocol { get; }Property value
RemoteCertificate
MsQuicConnection.csGets the certificate of the server, for a client connection.
public X509Certificate2? RemoteCertificate { get; }Property value
RemoteEndPoint
MsQuicConnection.csTargetHostName
MsQuicConnection.csMethods
| Name | Description |
|---|---|
| AcceptInboundStreamAsync(CancellationToken) | Waits for the next stream the peer opens. |
| CloseAsync(long, CancellationToken) | Closes the connection with an application error code, and waits until the peer is notified. |
| ConnectAsync(MsQuicClientConnectionOptions, CancellationToken) | Connects to a QUIC server. |
| DisposeAsync() | Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously. |
| GetStatistics() | Gets the statistics of the connection: round-trip time, bytes and packets sent and received, losses... |
| OpenOutboundStreamAsync(MsQuicStreamType, bool, CancellationToken) | Opens a stream. |
| OpenOutboundStreamAsync(MsQuicStreamType, CancellationToken) | Opens a stream. |
| ReceiveDatagramAsync(CancellationToken) | Waits for the next datagram the peer sends. |
| SendDatagramAsync(ReadOnlyMemory<byte>, CancellationToken) | Sends a QUIC datagram (RFC 9221). Datagrams are not retransmitted: the peer may not receive it. |
AcceptInboundStreamAsync(CancellationToken)
MsQuicConnection.csWaits for the next stream the peer opens.
net10.0
public ValueTask<MsQuicStream> AcceptInboundStreamAsync(CancellationToken cancellationToken = default)net11.0
public ValueTask<MsQuicStream> AcceptInboundStreamAsync(CancellationToken cancellationToken = default)Parameters
cancellationTokenCancellationToken
Returns
Exceptions
MsQuicException- The connection is closed.
CloseAsync(long, CancellationToken)
MsQuicConnection.csCloses the connection with an application error code, and waits until the peer is notified.
net10.0
public ValueTask CloseAsync(long errorCode, CancellationToken cancellationToken = default)net11.0
public ValueTask CloseAsync(long errorCode, CancellationToken cancellationToken = default)Parameters
errorCodelong- The application error code, from 0 to 2^62-1.
cancellationTokenCancellationToken- The token to stop waiting.
Returns
ConnectAsync(MsQuicClientConnectionOptions, CancellationToken)
MsQuicConnection.csConnects to a QUIC server.
net10.0
public static ValueTask<MsQuicConnection> ConnectAsync(MsQuicClientConnectionOptions options, CancellationToken cancellationToken = default)net11.0
public static ValueTask<MsQuicConnection> ConnectAsync(MsQuicClientConnectionOptions options, CancellationToken cancellationToken = default)Parameters
optionsMsQuicClientConnectionOptionscancellationTokenCancellationToken
Returns
Exceptions
PlatformNotSupportedException- MsQuic is not available.
MsQuicException- The connection failed.
DisposeAsync()
MsQuicConnection.csGetStatistics()
MsQuicConnection.csGets the statistics of the connection: round-trip time, bytes and packets sent and received, losses...
public MsQuicConnectionStatistics GetStatistics()Returns
OpenOutboundStreamAsync overloads
OpenOutboundStreamAsync(MsQuicStreamType, bool, CancellationToken)
MsQuicConnection.csOpens a stream.
net10.0
public ValueTask<MsQuicStream> OpenOutboundStreamAsync(MsQuicStreamType type, bool waitUntilAvailable, CancellationToken cancellationToken = default)net11.0
public ValueTask<MsQuicStream> OpenOutboundStreamAsync(MsQuicStreamType type, bool waitUntilAvailable, CancellationToken cancellationToken = default)Parameters
typeMsQuicStreamType- The type of the stream.
waitUntilAvailablebooltrueto wait until the peer allows one more stream;falseto fail withMsQuicError.StreamLimitReachedwhen it does not allow one now.cancellationTokenCancellationToken- The token to cancel the operation.
Returns
OpenOutboundStreamAsync(MsQuicStreamType, CancellationToken)
MsQuicConnection.csOpens a stream.
public ValueTask<MsQuicStream> OpenOutboundStreamAsync(MsQuicStreamType type, CancellationToken cancellationToken = default)Parameters
typeMsQuicStreamType- The type of the stream.
cancellationTokenCancellationToken- The token to cancel the operation.
Returns
ValueTask<MsQuicStream> The stream, once the peer allows it (its stream limit).
ReceiveDatagramAsync(CancellationToken)
MsQuicConnection.csWaits for the next datagram the peer sends.
net10.0
public ValueTask<byte[]> ReceiveDatagramAsync(CancellationToken cancellationToken = default)net11.0
public ValueTask<byte[]> ReceiveDatagramAsync(CancellationToken cancellationToken = default)Parameters
cancellationTokenCancellationToken
Returns
Exceptions
MsQuicException- The connection is closed.
SendDatagramAsync(ReadOnlyMemory<byte>, CancellationToken)
MsQuicConnection.csSends a QUIC datagram (RFC 9221). Datagrams are not retransmitted: the peer may not receive it.
public Task SendDatagramAsync(ReadOnlyMemory<byte> datagram, CancellationToken cancellationToken = default)Parameters
datagramReadOnlyMemory<byte>- The payload, at most
MsQuicConnection.MaxDatagramSendSizebytes. cancellationTokenCancellationToken- The token to stop waiting. The datagram is still sent.
Returns
Task A task that completes when the datagram is sent on the network.
Exceptions
MsQuicException- Datagrams are not enabled, the datagram is too large, or the connection closed before it was sent.