QUIC connections

edit

MsQuicConnection, MsQuicListener and MsQuicStream follow the shape of QuicConnection, QuicListener and QuicStream of System.Net.Quic. See Getting started for a complete example.

Connect and listen

  • MsQuicConnection.ConnectAsync takes MsQuicClientConnectionOptions: the address (an IPEndPoint, or a DnsEndPoint whose addresses are tried in order) and the TLS options. The application protocols (ALPN) are required.
  • The certificate of the server is validated like SslStream does. RemoteCertificateValidationCallback can decide instead, for instance to accept a certificate by its hash.
  • MsQuicListener.ListenAsync takes the address and the application protocols, and a callback that returns the options of each connection, from its server name. Return the same MsQuicServerConnectionOptions instance for the same options: the listener caches the configuration of each instance.

Datagrams

Datagrams are unreliable and unordered. Both sides must set EnableDatagrams before either can send one.

Streams

  • OpenOutboundStreamAsync waits until the peer allows one more stream, or fails with StreamLimitReached when waitUntilAvailable is false.
  • AcceptInboundStreamAsync returns the streams the peer opens.
  • WriteAsync with completeWrites: true sends the data and the end of the stream in the same packet. Abort sends RESET_STREAM or STOP_SENDING with an application error code, which the peer reads in MsQuicException.ApplicationErrorCode.
  • Priority goes from 0 to 65535: the data of the streams with a higher priority is sent first.
  • Canceling a read or a write aborts that side of the stream.

Statistics and congestion control

GetStatistics returns the round-trip time, the bytes and packets sent and received, the lost packets and the congestion window. CongestionControlAlgorithm picks CUBIC or BBR.

Close

CloseAsync closes the connection with an application error code. Closed completes with the reason the connection closed: the error code of the peer, the idle timeout... Dispose the connections, the streams and the listeners: MsQuic keeps a connection alive until it is closed.