WebTransportSession Class
A WebTransport session over HTTP/3 (draft-ietf-webtrans-http3): bidirectional and unidirectional streams, and datagrams.
public sealed class WebTransportSession : IAsyncDisposableRemarks
Connect to a server with WebTransportSession.ConnectAsync, or accept a session with WebTransportSessionRequest.AcceptAsync. A client session has its own QUIC connection, closed with the session. Dispose the session to close it.
- Implements
Properties
| Name | Description |
|---|---|
| Closed | Gets a task that completes when the session is closed cleanly, with the error code and the reason of the CLOSE_WEBTRANSPORT_SESSION capsule (0 and an empty reason when the CONNECT stream ends without one). It faults with a WebTransportException when the session ends abruptly. |
| Draining | Gets a task that completes when the peer asks to end the session gracefully (DRAIN_WEBTRANSPORT_SESSION capsule, or GOAWAY). |
| MaxDatagramSize | Gets the maximum size of a datagram payload. It can grow during the session, and is 0 when datagrams cannot be sent. |
| Protocol | Gets the application protocol the server picked from the protocols the client offered (wt-protocol), if any. |
| RemoteCertificate | Gets the certificate of the server, for a client session. |
| RemoteEndPoint | Gets the address of the peer. |
| ResponseHeaders | Gets the headers of the response to the CONNECT request, without the pseudo-headers. |
| SessionId | Gets the identifier of the session: the identifier of its CONNECT stream. |
Closed
WebTransportSession.csGets a task that completes when the session is closed cleanly, with the error code and the reason of the CLOSE_WEBTRANSPORT_SESSION capsule (0 and an empty reason when the CONNECT stream ends without one). It faults with a WebTransportException when the session ends abruptly.
public Task<WebTransportCloseInfo> Closed { get; }Property value
Draining
WebTransportSession.csMaxDatagramSize
WebTransportSession.csProtocol
WebTransportSession.csRemoteCertificate
WebTransportSession.csGets the certificate of the server, for a client session.
public X509Certificate2? RemoteCertificate { get; }Property value
RemoteEndPoint
WebTransportSession.csResponseHeaders
WebTransportSession.csGets the headers of the response to the CONNECT request, without the pseudo-headers.
public IReadOnlyList<KeyValuePair<string, string>> ResponseHeaders { get; }Property value
SessionId
WebTransportSession.csMethods
| Name | Description |
|---|---|
| AcceptStreamAsync(CancellationToken) | Waits for the next stream the peer opens. |
| CloseAsync(uint, string, CancellationToken) | Closes the session with an application error code and a reason (CLOSE_WEBTRANSPORT_SESSION capsule). Its streams are aborted. |
| ConnectAsync(Uri, WebTransportClientOptions?, CancellationToken) | Opens a WebTransport session to a server. |
| DisposeAsync() | Closes the session if it is open, with error code 0, and releases its resources. |
| DrainAsync(CancellationToken) | Asks the peer to end the session gracefully (DRAIN_WEBTRANSPORT_SESSION capsule). The session stays open. |
| GetConnectionStatistics() | Gets the statistics of the QUIC connection of the session. |
| OpenBidirectionalStreamAsync(bool, CancellationToken) | Opens a bidirectional stream. |
| OpenUnidirectionalStreamAsync(bool, CancellationToken) | Opens a unidirectional stream. |
| ReceiveDatagramAsync(CancellationToken) | Waits for the next datagram of the session. When the queue is full, the oldest datagrams are dropped. |
| SendDatagramAsync(ReadOnlyMemory<byte>, CancellationToken) | Sends a datagram. Datagrams are not retransmitted: the peer may not receive it. |
AcceptStreamAsync(CancellationToken)
WebTransportSession.csWaits for the next stream the peer opens.
net10.0
public ValueTask<WebTransportStream> AcceptStreamAsync(CancellationToken cancellationToken = default)net11.0
public ValueTask<WebTransportStream> AcceptStreamAsync(CancellationToken cancellationToken = default)Parameters
cancellationTokenCancellationToken
Returns
Exceptions
WebTransportException- The session is closed.
CloseAsync(uint, string, CancellationToken)
WebTransportSession.csCloses the session with an application error code and a reason (CLOSE_WEBTRANSPORT_SESSION capsule). Its streams are aborted.
net10.0
public ValueTask CloseAsync(uint errorCode = 0U, string reason = "", CancellationToken cancellationToken = default)net11.0
public ValueTask CloseAsync(uint errorCode = 0U, string reason = "", CancellationToken cancellationToken = default)Parameters
errorCodeuint- The application error code.
reasonstring- The reason, at most 1024 bytes in UTF-8.
cancellationTokenCancellationToken- The token to stop waiting for the peer to receive the capsule.
Returns
ConnectAsync(Uri, WebTransportClientOptions?, CancellationToken)
WebTransportSession.csOpens a WebTransport session to a server.
net10.0
public static ValueTask<WebTransportSession> ConnectAsync(Uri uri, WebTransportClientOptions? options = null, CancellationToken cancellationToken = default)net11.0
public static ValueTask<WebTransportSession> ConnectAsync(Uri uri, WebTransportClientOptions? options = null, CancellationToken cancellationToken = default)Parameters
uriUri- The
httpsURL of the session. optionsWebTransportClientOptions?- The options.
cancellationTokenCancellationToken- The token to cancel the operation.
Returns
ValueTask<WebTransportSession>
Exceptions
WebTransportException- The connection failed, the server does not support WebTransport, or it rejected the session.
PlatformNotSupportedException- MsQuic is not available.
DisposeAsync()
WebTransportSession.csDrainAsync(CancellationToken)
WebTransportSession.csAsks the peer to end the session gracefully (DRAIN_WEBTRANSPORT_SESSION capsule). The session stays open.
net10.0
public ValueTask DrainAsync(CancellationToken cancellationToken = default)net11.0
public ValueTask DrainAsync(CancellationToken cancellationToken = default)GetConnectionStatistics()
WebTransportSession.csGets the statistics of the QUIC connection of the session.
public MsQuicConnectionStatistics GetConnectionStatistics()Returns
OpenBidirectionalStreamAsync(bool, CancellationToken)
WebTransportSession.csOpens a bidirectional stream.
public ValueTask<WebTransportStream> OpenBidirectionalStreamAsync(bool waitUntilAvailable = true, CancellationToken cancellationToken = default)Parameters
waitUntilAvailablebooltrueto wait until the peer allows one more stream;falseto fail when it does not allow one now.cancellationTokenCancellationToken- The token to cancel the operation.
Returns
OpenUnidirectionalStreamAsync(bool, CancellationToken)
WebTransportSession.csOpens a unidirectional stream.
public ValueTask<WebTransportStream> OpenUnidirectionalStreamAsync(bool waitUntilAvailable = true, CancellationToken cancellationToken = default)Parameters
waitUntilAvailablebooltrueto wait until the peer allows one more stream;falseto fail when it does not allow one now.cancellationTokenCancellationToken- The token to cancel the operation.
Returns
ReceiveDatagramAsync(CancellationToken)
WebTransportSession.csWaits for the next datagram of the session. When the queue is full, the oldest datagrams are dropped.
net10.0
public ValueTask<ReadOnlyMemory<byte>> ReceiveDatagramAsync(CancellationToken cancellationToken = default)net11.0
public ValueTask<ReadOnlyMemory<byte>> ReceiveDatagramAsync(CancellationToken cancellationToken = default)Parameters
cancellationTokenCancellationToken
Returns
ValueTask<ReadOnlyMemory<byte>>
Exceptions
WebTransportException- The session is closed.
SendDatagramAsync(ReadOnlyMemory<byte>, CancellationToken)
WebTransportSession.csSends a datagram. Datagrams are not retransmitted: the peer may not receive it.
net10.0
public Task SendDatagramAsync(ReadOnlyMemory<byte> datagram, CancellationToken cancellationToken = default)net11.0
public Task SendDatagramAsync(ReadOnlyMemory<byte> datagram, CancellationToken cancellationToken = default)Parameters
datagramReadOnlyMemory<byte>- The payload, at most
WebTransportSession.MaxDatagramSizebytes. cancellationTokenCancellationToken- The token to stop waiting.
Returns
Task A task that completes when the datagram is sent on the network.