Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. WebTransportDatagramDuplexStream

WebTransportDatagramDuplexStream

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Secure context: This feature is available only insecure contexts (HTTPS), in some or allsupporting browsers.

Note: This feature is available inWeb Workers.

TheWebTransportDatagramDuplexStream interface of theWebTransport API represents a duplex stream that can be used for unreliable transport of datagrams between client and server. Provides access to aReadableStream for reading incoming datagrams, aWritableStream for writing outgoing datagrams, and various settings and statistics related to the stream.

This is accessed via theWebTransport.datagrams property.

"Unreliable" means that transmission of data is not guaranteed, nor is arrival in a specific order. This is fine in some situations and provides very fast delivery. For example, you might want to transmit regular game state updates where each message supersedes the last one that arrives, and order is not important.

Instance properties

incomingHighWaterMark

Gets or sets the high water mark for incoming chunks of data — this is the maximum size, in chunks, that the incomingReadableStream's internal queue can reach before it is considered full. SeeInternal queues and queuing strategies for more information.

incomingMaxAge

Gets or sets the maximum age for incoming datagrams, in milliseconds. Returnsnull if no maximum age has been set.

maxDatagramSizeRead only

Returns the maximum allowable size of outgoing datagrams, in bytes, that can be written towritable.

outgoingHighWaterMark

Gets or sets the high water mark for outgoing chunks of data — this is the maximum size, in chunks, that the outgoingWritableStream's internal queue can reach before it is considered full. SeeInternal queues and queuing strategies for more information.

outgoingMaxAge

Gets or sets the maximum age for outgoing datagrams, in milliseconds. Returnsnull if no maximum age has been set.

readableRead only

Returns aReadableStream instance that can be used to read incoming datagrams from the stream.

writableRead onlyDeprecated

Returns aWritableStream instance that can be used to write outgoing datagrams to the stream.

Examples

Writing outgoing datagrams

Thewritable property returns aWritableStream object that you can write data to using a writer, for transmission to the server:

js
const writer = transport.datagrams.writable.getWriter();const data1 = new Uint8Array([65, 66, 67]);const data2 = new Uint8Array([68, 69, 70]);writer.write(data1);writer.write(data2);

Reading incoming datagrams

Thereadable property returns aReadableStream object that you can use to receive data from the server:

js
async function readData() {  const reader = transport.datagrams.readable.getReader();  while (true) {    const { value, done } = await reader.read();    if (done) {      break;    }    // value is a Uint8Array.    console.log(value);  }}

Specifications

Specification
WebTransport
# webtransportdatagramduplexstream

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp