QUIC connections
editMsQuicConnection, 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 aDnsEndPointwhose addresses are tried in order) and the TLS options. The application protocols (ALPN) are required. - The certificate of the server is validated like
SslStreamdoes.RemoteCertificateValidationCallbackcan 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.
- IsDatagramSendEnabled tells whether datagrams can be sent now.
- MaxDatagramSendSize can grow during the connection, as path MTU discovery finds a larger MTU: read it before each send.
- SendDatagramAsync completes when the datagram is sent on the network, and throws an MsQuicException for a datagram that is too large.
- ReceiveDatagramAsync returns the next datagram. When the application does not read them fast enough, the oldest are dropped, beyond ReceivedDatagramQueueCapacity.
Streams
- OpenOutboundStreamAsync waits until the peer allows one more stream, or fails with
StreamLimitReachedwhenwaitUntilAvailableisfalse. - AcceptInboundStreamAsync returns the streams the peer opens.
WriteAsyncwithcompleteWrites: truesends 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.