This specification defines an API that allows web applications to talk to servers and devices that have their own protocols incompatible with those available on the web.
[
Exposed=(Window,DedicatedWorker),
SecureContext,
IsolatedContext
]
interface TCPSocket {
constructor(DOMString remoteAddress,
unsigned short remotePort,
optional TCPSocketOptions options = {});
readonly attribute Promise<TCPSocketOpenInfo> opened;
readonly attribute Promise<undefined> closed;
Promise<undefined> close();
};
Methods on this interface typically complete asynchronously, queuing work on the TCPSocket task source.
Instances of {{TCPSocket}} are created with the internal slots described in the following table:
| Internal slot | Initial value | Description (non-normative) |
|---|---|---|
| [[\readable]] | `null` | A {{ReadableStream}} that receives data from the socket |
| [[\writable]] | `null` | A {{WritableStream}} that transmits data to the socket |
| [[\openedPromise]] | `new Promise` | A {{Promise}} used to wait for the socket to be opened. Corresponds to the {{TCPSocket/opened}} member. |
[[\closedPromise]]
| `new Promise`
| A {{Promise}} used to wait for the socket to close or error. Corresponds to the
{{TCPSocket/closed}} member.
| |
enum SocketDnsQueryType {
"ipv4",
"ipv6"
};
dictionary TCPSocketOptions {
[EnforceRange] unsigned long sendBufferSize;
[EnforceRange] unsigned long receiveBufferSize;
boolean noDelay = false;
[EnforceRange] unsigned long keepAliveDelay;
SocketDnsQueryType dnsQueryType;
};
dictionary TCPSocketOpenInfo {
ReadableStream readable;
WritableStream writable;
DOMString remoteAddress;
unsigned short remotePort;
DOMString localAddress;
unsigned short localPort;
};
[
Exposed=(Window,DedicatedWorker),
SecureContext,
IsolatedContext
]
interface UDPSocket {
constructor(optional UDPSocketOptions options = {});
readonly attribute Promise<UDPSocketOpenInfo> opened;
readonly attribute Promise<undefined> closed;
Promise<undefined> close();
};
Methods on this interface typically complete asynchronously, queuing work on the
UDPSocket task source.
Instances of {{UDPSocket}} are created with the internal slots described in the following table:
| Internal slot | Initial value | Description (non-normative) |
|---|---|---|
| [[\readable]] | `null` | A {{ReadableStream}} that receives data from the socket |
| [[\writable]] | `null` | A {{WritableStream}} that transmits data to the socket |
| [[\openedPromise]] | `new Promise` | A {{Promise}} used to wait for the socket to be opened. Corresponds to the {{UDPSocket/opened}} member. |
[[\closedPromise]]
| `new Promise`
| A {{Promise}} used to wait for the socket to close or error. Corresponds to the
{{UDPSocket/closed}} member.
| |
dictionary UDPSocketOptions {
DOMString remoteAddress;
[EnforceRange] unsigned short remotePort;
DOMString localAddress;
[EnforceRange] unsigned short localPort;
[EnforceRange] unsigned long sendBufferSize;
[EnforceRange] unsigned long receiveBufferSize;
SocketDnsQueryType dnsQueryType;
boolean ipv6Only;
[EnforceRange] octet multicastTimeToLive;
boolean multicastLoopback;
boolean multicastAllowAddressSharing;
};
dictionary UDPMessage {
BufferSource data;
DOMString remoteAddress;
unsigned short remotePort;
SocketDnsQueryType dnsQueryType;
};
dictionary UDPSocketOpenInfo {
ReadableStream readable;
WritableStream writable;
DOMString remoteAddress;
unsigned short remotePort;
DOMString localAddress;
unsigned short localPort;
MulticastController multicastController;
};
The {{MulticastController}} interface provides methods to join and leave multicast groups and to inspect which groups have been joined. It supports both Any-Source Multicast (ASM) and Source-Specific Multicast (SSM). An instance of this interface is obtained from the {{UDPSocketOpenInfo/multicastController}} member of the dictionary returned by the {{UDPSocket/opened}} promise. This member is only present if the socket is in {{UDPSocket/bound}} {{UDPSocket/mode}} and and [=this=]'s [=relevant global object=]'s [=associated Document=] is [=allowed to use=] the [=policy-controlled feature=] named "[=policy-controlled feature/direct-sockets-multicast=]".
dictionary MulticastGroupOptions {
DOMString sourceAddress;
};
dictionary MulticastMembership {
DOMString groupAddress;
DOMString sourceAddress;
};
[
Exposed=(Window, DedicatedWorker),
SecureContext,
IsolatedContext
]
interface MulticastController {
Promise<undefined> joinGroup(DOMString groupAddress, optional MulticastGroupOptions options = {});
Promise<undefined> leaveGroup(DOMString groupAddress, optional MulticastGroupOptions options = {});
readonly attribute FrozenArray<(DOMString or MulticastMembership)> joinedGroups;
};
The {{MulticastGroupOptions}} dictionary is used to specify options when joining or leaving a multicast group.
The {{MulticastMembership}} dictionary represents a multicast group membership, which may be either Any-Source Multicast (ASM) or Source-Specific Multicast (SSM).
Methods on this interface typically complete asynchronously, queuing work on the [=UDPSocket task source=].
Instances of {{MulticastController}} are created with the internal slots described in the following table:
| Internal slot | Description (non-normative) |
|---|---|
| [[\socket]] | The {{UDPSocket}} that this {{MulticastController}} manages multicast membership for. |
| [[\joinedGroups]] | A set of {{MulticastMembership}} objects representing the multicast group memberships (both ASM and SSM) that have been successfully joined, ordered from the earliest joined membership to the latest. |
The {{MulticastController/joinGroup(groupAddress, options)}} method joins the multicast group at the given `groupAddress` and the `localPort` it was bound to. If `options.sourceAddress` is provided, this creates a Source-Specific Multicast (SSM) membership that only receives packets from that specific source. If `options.sourceAddress` is omitted, this creates an Any-Source Multicast (ASM) membership that receives packets from any source.
The {{MulticastController/joinGroup(groupAddress, options)}} method steps are:The {{MulticastController/leaveGroup(groupAddress, options)}} method leaves a multicast group previously joined via {{MulticastController/joinGroup(groupAddress, options)}}. The `groupAddress` and `options.sourceAddress` must match those used when joining the group.
The {{MulticastController/joinedGroups}} getter steps are:
Any-Source Multicast (ASM) memberships are represented as {{DOMString}} values (the group address) for backward compatibility, while Source-Specific Multicast (SSM) memberships are represented as {{MulticastMembership}} objects containing both group and source addresses.
[
Exposed=(Window,DedicatedWorker),
SecureContext,
IsolatedContext
]
interface TCPServerSocket {
constructor(DOMString localAddress,
optional TCPServerSocketOptions options = {});
readonly attribute Promise<TCPServerSocketOpenInfo> opened;
readonly attribute Promise<undefined> closed;
Promise<undefined> close();
};
Methods on this interface typically complete asynchronously, queuing work on the TCPServerSocket task source.
Instances of {{TCPServerSocket}} are created with the internal slots described in the following table:
| Internal slot | Initial value | Description (non-normative) |
|---|---|---|
| [[\readable]] | `null` | A {{ReadableStream}} used to accept incoming connections. |
| [[\openedPromise]] | `new Promise` | A {{Promise}} used to wait for the socket to be opened. Corresponds to the {{TCPServerSocket/opened}} member. |
[[\closedPromise]]
| `new Promise`
| A {{Promise}} used to wait for the socket to close or error. Corresponds to the
{{TCPServerSocket/closed}} member.
| |
dictionary TCPServerSocketOptions {
[EnforceRange] unsigned short localPort;
[EnforceRange] unsigned long backlog;
boolean ipv6Only;
};
dictionary TCPServerSocketOpenInfo {
ReadableStream readable;
DOMString localAddress;
unsigned short localPort;
};
This specification defines a feature that controls whether {{TCPSocket}}, {{UDPSocket}} and {{TCPServerSocket}} classes may be created.
The feature name for this feature is "direct-sockets"`.
The default allowlist for this feature is `'none'`.
This specification defines a feature that controls whether {{TCPSocket}} and {{UDPSocket}} classes might connect to addresses belonging to the [=IP address space/private=] network address space.
The feature name for this feature is "direct-sockets-private"`.
The default allowlist for this feature is `'none'`.
This specification defines a feature that controls whether an application can receive multicast packets using {{UDPSocket}} and {{MulticastController}}.
The feature name for this feature is "direct-sockets-multicast"`.
The default allowlist for this feature is `'none'`.