MDN Web Docs

Syntax

js

getWriter()

Parameters

None.

Return value

A WebTransportWriter object instance.

Exceptions

TypeError

The stream is already locked to another writer.

Examples

The following example shows how to open a unidirectional stream over a WebTransport connection and use getWriter() to write chunks of data to it.

js

const transport = new WebTransport("https://example.com/webtransport");
await transport.ready;
const stream = await transport.createUnidirectionalStream();
const writer = stream.getWriter();
const encoder = new TextEncoder();
await writer.write(encoder.encode("Hello"));
await writer.write(encoder.encode(", world!"));
await writer.close();

Specifications

Specification
WebTransport
# dom-webtransportsendstream-getwriter

Browser compatibility

See also

Help improve MDN

Yes No

Learn how to contribute

This page was last modified on by MDN contributors.

Read the original on developer.mozilla.org ↗