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,Worker), SecureContext] 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.
| |
dictionary TCPSocketOptions { [EnforceRange] unsigned long sendBufferSize; [EnforceRange] unsigned long receiveBufferSize; boolean noDelay = false; [EnforceRange] unsigned long keepAliveDelay; };
dictionary TCPSocketOpenInfo { ReadableStream readable; WritableStream writable; DOMString remoteAddress; unsigned short remotePort; DOMString localAddress; unsigned short localPort; };
[Exposed=(Window,Worker), SecureContext] interface UDPSocket { constructor(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 { required DOMString remoteAddress; [EnforceRange] required unsigned short remotePort; [EnforceRange] unsigned long sendBufferSize; [EnforceRange] unsigned long receiveBufferSize; };
dictionary UDPMessage { BufferSource data; DOMString remoteAddress; unsigned short remotePort; };
dictionary UDPSocketOpenInfo { ReadableStream readable; WritableStream writable; DOMString remoteAddress; unsigned short remotePort; DOMString localAddress; unsigned short localPort; };
This specification defines a feature that controls whether {{TCPSocket}} and {{UDPSocket}} classes may be created.
The feature name for this feature is "direct-sockets
"`.
The default allowlist for this feature is `'self'`.