Limited availability
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
Note: This feature is available in Web Workers.
The WebTransportDatagramDuplexStream
interface of the WebTransport API represents a duplex stream that can be used for unreliable transport of datagrams between client and server. Provides access to a ReadableStream
for reading incoming datagrams, a WritableStream
for writing outgoing datagrams, and various settings and statistics related to the stream.
This is accessed via the WebTransport.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 propertiesincomingHighWaterMark
Gets or sets the high water mark for incoming chunks of data â this is the maximum size, in chunks, that the incoming ReadableStream
's internal queue can reach before it is considered full. See Internal queues and queuing strategies for more information.
incomingMaxAge
Gets or sets the maximum age for incoming datagrams, in milliseconds. Returns null
if no maximum age has been set.
maxDatagramSize
Read only
Returns the maximum allowable size of outgoing datagrams, in bytes, that can be written to writable
.
outgoingHighWaterMark
Gets or sets the high water mark for outgoing chunks of data â this is the maximum size, in chunks, that the outgoing WritableStream
's internal queue can reach before it is considered full. See Internal queues and queuing strategies for more information.
outgoingMaxAge
Gets or sets the maximum age for outgoing datagrams, in milliseconds. Returns null
if no maximum age has been set.
readable
Read only
Returns a ReadableStream
instance that can be used to read incoming datagrams from the stream.
writable
Read only Deprecated
Returns a WritableStream
instance that can be used to write outgoing datagrams to the stream.
The writable
property returns a WritableStream
object that you can write data to using a writer, for transmission to the server:
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
The readable
property returns a ReadableStream
object that you can use to receive data from the server:
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 Browser compatibility See also
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4