Copyright © 2013 W3C® (MIT, ERCIM, Keio, Beihang), All Rights Reserved. W3C liability, trademark and document use rules apply.
This API provides interfaces to raw UDP sockets, TCP client sockets and TCP server sockets.
This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at http://www.w3.org/TR/.
This document defines a System Level API for network communication over UDP and TCP sockets.
This document was published by the System Applications Working Group as a First Public Working Draft. This document is intended to become a W3C Recommendation. If you wish to make comments regarding this document, please send them to public-sysapps@w3.org (subscribe, archives). All feedback is welcome.
Publication as a First Public Working Draft does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.
This document was produced by a group operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.
UDPSocket
TCPSocket
TCPServerSocket
UDPMessageEvent
ConnectEvent
ErrorEvent
UDPOptions
TCPOptions
TCPServerOptions
This section is non-normative.
Use this API to send and receive data over the network using TCP or UDP.
As well as sections marked as non-normative, all authoring guidelines, diagrams, examples, and notes in this specification are non-normative. Everything else in this specification is normative.
The key words MUST, MUST NOT, REQUIRED, SHOULD, SHOULD NOT, RECOMMENDED, MAY, and OPTIONAL in this specification are to be interpreted as described in [RFC2119].
This specification defines conformance criteria that apply to a single product: the user agent that implements the interfaces that it contains.
Implementations that use ECMAScript to implement the APIs defined in this specification MUST implement them in a manner consistent with the ECMAScript Bindings defined in the Web IDL specification [WEBIDL], as this specification uses that specification and terminology.
The EventHandler
interface represents a callback used for event handlers as
defined in [HTML5].
The concepts queue a task and fire a simple event are defined in [HTML5].
The terms event handler and event handler event types are defined in [HTML5].
This API must be only exposed to trusted content.
UDPSocketThe UDPSocket interface defines
attributes and methods for UDP communication
// // This example shows a simple implementation of UPnP-SSDP M-SEARCH discovery // using a multicast UDPSocket // // Create a UDP socket var mySocket = new UDPSocket (); // Build an SSDP M-SEARCH multicast message var MSearch = "M-SEARCH * HTTP/1.1\r\n" + "ST: " + ServiceType + "\r\n" + "MAN: \"ssdp:discover\"\r\n" + "HOST: 239.255.255.250:1900\r\n" + "MX: 10\r\n\r\n"; var SSDPMulticastAddress = "239.255.255.250"; var SSDPMulticastPort = 1900; // Join multicast group mySocket.joinMulticastGroup (SSDPMulticastAddress); try { // Send SSDP M-SEARCH multicast message var moreBufferingOK = mySocket.send(MSearch, SSDPMulticastAddress, SSDPMulticastPort); console.log('M-SEARCH Sent!'); } catch(err) { // Sending failed console.error('Sending M-SEARCH failed: ' + err.name); } // Receive M-SEARCH responses mysocket.onmessage = function (udpMessageEvent) { // Convert received data from ArrayBuffer to string var data = arrayBufferToString (udpMessageEvent.data); console.log("Remote address: " + udpMessageEvent.remoteAddress + " Remote port: " + udpMessageEvent.remotePort + " Received data" + data); };
// // This example shows a a simple implementation of reception of UPnP-SSDP // NOTIFY multicast messages // var SSDPMulticastAddress = "239.255.255.250"; var SSDPMulticastPort = 1900; // Create a UDP socket and bind it to the IP-address of the default // local interface and to the SSDP local port var mySocket = new UDPSocket ({"localPort":SSDPMulticastPort}); // Join multicast group mySocket.joinMulticastGroup (SSDPMulticastAddress); // Receive SSDP NOTFIY mysocket.onmessage = function (UDPMessageEvent) { // Convert received data from ArrayBuffer to string var data = arrayBufferToString (UDPMessageEvent.data); console.log("Remote address: " + UDPMessageEvent.remoteAddress + " Remote port: " + UDPMessageEvent.remotePort + " Received data" + data); };
[Constructor (optional UDPOptions options)]
interface UDPSocket : EventTarget {
readonly attribute DOMString localAddress;
readonly attribute unsigned short localPort;
readonly attribute DOMString? remoteAddress;
readonly attribute unsigned short? remotePort;
readonly attribute boolean addressReuse;
readonly attribute boolean loopback;
readonly attribute unsigned long bufferedAmount;
readonly attribute ReadyState readyState;;
attribute EventHandler ondrain;
attribute EventHandler onerror;
attribute EventHandler onmessage;
void close ();
void suspend ();
void resume ();
void joinMulticastGroup (DOMString multicastGroupAddress);
void leaveMulticastGroup (DOMString multicastGroupAddress);
boolean send ((DOMString or Blob or ArrayBuffer or ArrayBufferView) data, optional DOMString? remoteAddress, optional unsigned short? remotePort);
};
addressReuse of type boolean, readonlytrue allows the socket to be bound to an
address that is already in use. Can be set by the
options argument in the constructor. Default
is true.bufferedAmount of type unsigned long, readonlylocalAddress of type DOMString, readonlyoptions argument in the constructor. If not
set the user agent binds the socket to the IPv4/6 address
of the default local interface.localPort of
type unsigned
short, readonlyoptions argument in the
constructor. If not set the user agent binds the socket to
a random local port number.loopback of
type boolean,
readonlytrue means that data you send is looped
back to your host. Can be set by the options
argument in the constructor. Default is
false.ondrain of
type EventHandler,onerror of
type EventHandler,onmessage of
type EventHandler,readyState;
of type ReadyState, readonlyremoteAddress of type DOMString, readonly ,
nullableremotePort
of type unsigned
short, readonly , nullablecloseCloses the UDP socket. A closed UDP socket can not be used any more.
void
joinMulticastGroupJoins a multicast group identified by the given address.
Note that even if the socket is only sending to a multicast address, it is a good practice to explicitely join the multicast group (otherwise some routers may not relay packets).
| Parameter | Type | Nullable | Optional | Description |
|---|---|---|---|---|
| multicastGroupAddress |
DOMString |
✘ | ✘ | The multicast group address. |
void
leaveMulticastGroupLeaves a multicast group membership identified by the given address.
| Parameter | Type | Nullable | Optional | Description |
|---|---|---|---|---|
| multicastGroupAddress |
DOMString |
✘ | ✘ | The multicast group address. |
void
resumeResume reading incoming UDP data and invoking
onmessage as usual.
void
sendSends data on the given UDP socket to the given address and port.
If remoteAddress and remotePort arguments are not
given or null the destination is the default address and
port given by the UDPSocket constructor's options
argument's remoteAddress and
remotePort fields.
| Parameter | Type | Nullable | Optional | Description |
|---|---|---|---|---|
| data | (DOMString or
Blob or ArrayBuffer or
ArrayBufferView) |
✘ | ✘ |
The data to write in one of the alternative
representations as stated below:
|
| remoteAddress |
DOMString |
✔ | ✔ | The address of the remote machine. |
| remotePort | unsigned
short |
✔ | ✔ | The port of the remote machine. |
boolean
suspendPause reading incoming UDP data and invocations of the
onmessage handler until resume is
called.
void
When the UDPSocket constructor is invoked,
the User Agent MUST run
the following steps:
options.localAddress argument is
absent then bind the socket to the IPv4/6 address of the
default local interface. Otherwise, if the requested local
address is free or if it is in use and the
options.addressReuse attribute is
true or absent then bind the socket to the
IPv4/6 address of the requested local interface. Else, throw
an InvalidAccessError exception and abort these
steps.options.localPort argument is absent
bind then the socket to any available local port. Otherwise,
if the requested local port is free or if it is in use and
the options.addressReuse attribute is
true or absent then bind the socket to the
requested local port. Else, throw an
InvalidAccessError exception and abort these
steps.options.remoteAddress field is
present then set the default remote address attribute of the
socket to the requested address.options.remotePort field is present
then set the default remote port attribute to the requested
port.UDPSocket object and if the
constructor's options argument is present set
the corresponding attributes to the values of the fields that
are present in the options argument, else set
the corresponding attributes to the default values.readyState attribute to "open".bufferedAmount attribute to 0.UDPSocket object to
the application.The send method when
invoked MUST run the
following steps:
readyState is "closed" throw DOMException
InvalidStateError and abort these steps.DOMString, Blob,
ArraYBuffer or ArrayBufferView,
then throw DOMException InvalidAccessError and
abort these steps.options.remoteAddress and
options.remotePort arguments and the send method arguments
remoteAddress and remotePort are
not present or null then throw DOMException
InvalidAccessError and abort these steps.ErrorEvent.
error.name attribute of the
ErrorEvent object to
"NetworkError".
error
with the newly created ErrorEvent instance
at the UDPSocket object.
readyState attribute to "closed".data parameter. If the send method arguments
remoteAddress and remotePort are
present use these as destination, else use the default
address and port of the recipient as stated by the UDPSocket
object constructor's options.remoteAddress and
options.remotePort fields.true or false as a
hint to the caller that they may either continue sending more
data immediately, or should want to wait until the transport
layer has transmitted buffered data that already have been
written to the socket before buffering more. When less than
an implementation specific value has been buffered and it's
safe to immediately write more set the return value to
true. When more than an implementation specific
value has been buffered set the return value to
false. This means that the caller should wait
before buffering more data by more calls to send until the
ondrain event handler has been called.bufferedAmount
attribute.
DOMString
the bufferedAmount attribute is increased by
the number of bytes needed to express the argument as
UTF-8. [UNICODE] [UTF-8]Blob the
bufferedAmount attribute is increased by the
size of the Blob object's raw data, in
bytes. [FILE-API]ArrayBuffer
the bufferedAmount attribute is increased by
the length of the ArrayBuffer in bytes.
[TYPED-ARRAYS]ArrayBufferView the
bufferedAmount attribute is increased by the
length of the ArrayBufferView in bytes.
[TYPED-ARRAYS]The close method when
invoked MUST run the
following steps:
readyState attribute to "closed".Upon a new UDP datagram being received, the user agent MUST run the following steps:
ArrayBuffer, [TYPED-ARRAYS], then:
ErrorEvent.
error.name attribute of the
ErrorEvent object to
"NetworkError".
error
with the newly created ErrorEvent instance
at the UDPSocket object.
UDPMessageEvent.
UDPMessageEvent object's
data attribute to a new read-only ArrayBuffer
object whose contents are the received UDP data
[TYPED-ARRAYS].
remoteAddress attribute of the
UDPMessageEvent object to the
source address of the received UDP datagram.
remotePort attribute of the
UDPMessageEvent object to the
source port of the received UDP datagram.
message
with the newly created UDPMessageEvent instance
at the UDPSocket object.
In the process of sending UDP data, upon a detection that previously-buffered data has been written to the network and it is possible to buffer more data received from the application, the user agent MUST:
drain at the
UDPSocket object.
The following are the event handlers (and their
corresponding event handler event types) that MUST be supported as attributes
by the UDPSocket object.
| event handler | event name |
|---|---|
onmessage |
message |
ondrain |
drain |
onerror |
error |
The message event SHALL implement the UDPMessageEvent interface.
The error event SHALL implement the ErrorEvent interface.
TCPSocketThe TCPSocket interface defines
attributes and methods for TCP communication
// // This example shows a simple TCP echo client. // The client will send "Hello World" to the server on port 6789 and log // what has been received from the server. // try { // Create a new TCP client socket and connect to remote host var mySocket = new TCPSocket ("127.0.0.1", 6789); mySocket.onopen = function() { try { // Send data to server var moreBufferingOK = mySocket.send("Hello World"); console.log('Data sent to server!'); // Receive response from server mySocket.onmessage = function (messageEvent) { // Convert received data from ArrayBuffer to string var data = arrayBufferToString (messageEvent.data); console.log('Data received from server: ' + data); // Close the connection mySocket.close(); } } catch(err) { // Sending failed console.error('Sending failed: ' + err.name); } } // Connection has been closed mySocket.onclose = function { console.log('Connection has been closed'); } // Handle errors mySocket.onerror = function(err) { console.error('Error: ' + err.name); } } catch(err) { // Handle runtime exception console.error('Could not create a TCP socket: ' + err.name); }
[Constructor (DOMString remoteAddress, unsigned short remotePort,
optional TCPOptions options)]
interface TCPSocket : EventTarget {
readonly attribute DOMString remoteAddress;
readonly attribute DOMString remotePort;
readonly attribute DOMString localAddress;
readonly attribute unsigned short localPort;
readonly attribute unsigned long bufferedAmount;
readonly attribute ReadyState readyState;;
attribute EventHandler ondrain;
attribute EventHandler onopen;
attribute EventHandler onclose;
attribute EventHandler onhalfclose;
attribute EventHandler onerror;
attribute EventHandler onmessage;
void close ();
void halfclose ();
void suspend ();
void resume ();
boolean send ((DOMString or Blob or ArrayBuffer or ArrayBufferView) data);
};
bufferedAmount of type unsigned long, readonlylocalAddress of type DOMString, readonlyoptions argument in the constructor. If not
set the user agent binds the socket to the IPv4/6 address
of the default local interface.localPort of
type unsigned
short, readonlyoptions argument in the
constructor. If not set the user agent binds the socket to
a random local port number.onclose of
type EventHandler,ondrain of
type EventHandler,onerror of
type EventHandler,onhalfclose of type EventHandler,onmessage of
type EventHandler,onopen of type
EventHandler,readyState;
of type ReadyState, readonlyremoteAddress of type DOMString, readonlyremotePort
of type DOMString,
readonlycloseCloses the TCP socket.
void
halfclose"Halfcloses" the TCP socket. This means that FIN is sent and that the socket no longer can be used to send data. However, receiving is still possible.
void
resumeResume reading incoming TCP data and invoking
onmessage as usual.
void
sendSends data on the given connected TCP socket.
| Parameter | Type | Nullable | Optional | Description |
|---|---|---|---|---|
| data | (DOMString or
Blob or ArrayBuffer or
ArrayBufferView) |
✘ | ✘ |
The data to write in one of the alternative
representations as stated below:
|
boolean
suspendPause reading incoming TCP data and invocations of the
onmessage handler until resume is
called.
void
When the TCPSocket constructor is invoked,
the User Agent MUST run
the following steps:
remoteAddress argument is not a valid
IPv4/6 address or the remotePort argument is not
a valid port number then throw an
InvalidAccessError exception and abort these
steps, else set the remoteAddress and
remotePort attributes to the requested
values.options.localAddress argument is
absent bind the socket to the IPv4/6 address of the default
local interface. Otherwise, if the requested local address is
free then bind the socket to the IPv4/6 address of the
requested local interface. Else, throw an
InvalidAccessError exception and abort these
steps.options.localPort argument is absent
bind then the socket to any available local port. Otherwise,
if the requested local port is free bind the socket to the
requested local port. Else, throw an
InvalidAccessError exception and abort these
steps.localAddress and
localPort attributes to the selected values
according to above.readyState attribute to
"connecting".bufferedAmount attribute to 0.TCPSocket object to the
application.
The send method when
invoked MUST run the
following steps:
readyState is not "open" throw
DOMException InvalidStateError and abort these
steps.DOMString, Blob,
ArraYBuffer or ArrayBufferView,
then throw DOMException InvalidAccessError and
abort these steps.readyState attribute's value
to "closed".ErrorEvent.
error.name attribute of the
ErrorEvent object to
"NetworkError".
error
with the newly created ErrorEvent instance
at the TCPSocket object.
close at
the TCPSocket object.
data parameter to the address and
port of the recipient as stated by the TCPSocket object
constructor's remoteAddress and
remotePort fields.true or false as a
hint to the caller that they may either continue sending more
data immediately, or should want to wait until the transport
layer has transmitted buffered data that already have been
written to the socket before buffering more. When less than
an implementation specific value has been buffered and it's
safe to immediately write more set the return value to
true. When more than an implementation specific
value has been buffered set the return value to
false. This means that the caller should wait
before buffering more data by more calls to send until the
ondrain event handler has been called.bufferedAmount
attribute.
DOMString
the bufferedAmount attribute is increased by
the number of bytes needed to express the argument as
UTF-8. [UNICODE] [UTF-8]Blob the
bufferedAmount attribute is increased by the
size of the Blob object's raw data, in
bytes. [FILE-API]ArrayBuffer
the bufferedAmount attribute is increased by
the length of the ArrayBuffer in bytes.
[TYPED-ARRAYS]ArrayBufferView the
bufferedAmount attribute is increased by the
length of the ArrayBufferView in bytes.
[TYPED-ARRAYS]The close method
when invoked MUST run the
following steps:
readyState is "closing" or "closed" then
do nothing.readyState is "connecting" then fail the
connection attempt and set the readyState
attribute to "closing".readyState is "open" close the connection
and set the readyState attribute to
"closing".The halfclose
method when invoked MUST
run the following steps:
readyState is "closing" or "closed" then
do nothing.readyState is "connecting" then complete
the connection attempt. If succesful send FIN and set the
readyState attribute to "halfclosed".readyState is "open" then send FIN and
set the readyState attribute to
"halfclosed".When a new TCP connection has been successfully established the user agent MUST run the following steps:
readyState attribute's value to
"open".open at the
TCPSocket object.
When the attempt to establish a new TCP connection
(readyState is "connecting") has failed the
user agent
MUST run the following
steps:
readyState attribute's value to
"closed".ErrorEvent.
error.name attribute of the
ErrorEvent object to
"NetworkError".
error with
the newly created ErrorEvent instance at the
TCPSocket object.
When an established TCP connection (readyState
is "open") is lost the user agent MUST run the following steps:
readyState attribute's value to
"closed".ErrorEvent.
error.name attribute of the
ErrorEvent object to
"NetworkError".
error with
the newly created ErrorEvent instance at the
TCPSocket object.
close at the
TCPSocket object.
Upon a new TCP message being received, the user agent MUST run the following steps:
ArrayBuffer, [TYPED-ARRAYS], then:
ErrorEvent.
error.name attribute of the
ErrorEvent object to
"NetworkError".
error
with the newly created ErrorEvent instance
at the UDPSocket object.
MessageEvent,
[POSTMSG].MessageEvent object's data
attribute to a new read-only ArrayBuffer object
whose contents are the received TCP data [TYPED-ARRAYS].message
with the newly created MessageEvent instance
at the TCPSocket object.
Note: It is up to the implementation the define how often
the message event will be issued and how
much data that will be delivered to the application with each
MessageEvent instance.
In the process of sending TCP data, upon a detection that previously-buffered data has been written to the network and it is possible to buffer more data received from the application, the user agent MUST:
drain at the
TCPSocket object.
When a TCP connection has been closed cleanly, either by the
server, or by the client calling close() the
user agent
MUST run the following
steps:
readyState attribute's value to
"closed".close at the
TCPSocket object.
The following are the event handlers (and their
corresponding event handler event types) that MUST be supported as attributes
by the TCPSocket object.
| event handler | event name |
|---|---|
onmessage |
message |
ondrain |
drain |
onopen |
open |
onclose |
close |
onhalfclose |
halfclose |
onerror |
error |
The message event SHALL implement the
MessageEvent interface, [POSTMSG]. The event's data
attribute is intialized to a new read-only
ArrayBuffer object whose contents are the
recieved UDP data. [TYPED-ARRAYS]
The error event SHALL implement the ErrorEvent interface.
TCPServerSocketThe TCPServerSocket interface supports
TCP server sockets that listens to connection attempts from TCP
clients
// // This example shows a simple TCP echo server. // The server will listen on port 6789 and respond back with what ever // has been sent to the server. // try { // Create a new server socket that listens on port 6789 var myServerSocket = new TCPServerSocket ({"localPort":6789}); myServerSocket.onconnect = function (connectEvent) { var connectedSocket = connectEvent.connectedSocket; // Read the data connectedSocket.onmessage = function (messageEvent) { var data = messageEvent.data; try { // Send data back to client var moreBufferingOK = connectedSocket.send(data); console.log('Response sent to client!'); } catch(err) { // Sending failed console.error('Sending failed: ' + err.name); } } // Connection has been closed connectedSocket.onclose = function { console.log('Connection has been closed'); } } } catch(err) { // Handle runtime exception console.error('Could not create a TCP server socket: ' + err.name); }
[Constructor (optional TCPServerOptions options)]
interface TCPServerSocket : EventTarget {
readonly attribute DOMString localAddress;
readonly attribute unsigned short localPort;
readonly attribute ReadyState readyState;;
attribute EventHandler onconnect;
attribute EventHandler onerror;
void close ();
void suspend ();
void resume ();
};
localAddress of type DOMString, readonlyoptions argument in the constructor. If
not set the user agent binds the socket to the IPv4/6
address of the default local interface.localPort of type unsigned short, readonlyoptions argument in the
constructor. If not set the user agent binds the socket to
a random local port number.onconnect of type EventHandler,onerror
of type EventHandler,readyState; of type ReadyState, readonlycloseCloses the TCP server socket, i.e. listening for incoming connections is stopped. Existing TCP connections are kept open.
void
resumeResume listening for incoming connections and
invocations of the onconnecion handler as
usual.
void
suspendPause listening for incoming connections and
invocations of the onconnecion handler until
resume() is called.
void
When the TCPServerSocket constructor is
invoked, the User Agent MUST run the following steps:
InvalidAccessError exception and abort these
steps.options.localAddress argument is
absent then listen to the IPv4/6 address of the default local
interface. Otherwise, if the requested local address is free
then listen to the IPv4/6 address of the requested local
interface. Else, throw an InvalidAccessError
exception and abort these steps.options.localPort argument is absent
then bind the socket to any available local port. Otherwise,
if the requested local port is free then bind the socket to
the requested local port. Else, throw an
InvalidAccessError exception and abort these
steps.TCPServerSocket object and set the
localAddress and localPort
attributes to selected values accoring to above.
readyState attribute to "open".TCPServerSocket object to the
application.
The close method
when invoked MUST run the
following steps:
readyState attribute to
"closed".Upon a new successful connection to the TCP server socket the user agent MUST run the following steps:
ConnectEvent.
TCPSocket.
remoteAddress attribute of
socket to the IPv4/6 address of the peer.remotePort attribute of
socket to the source port of the of the peer.localAddress attribute of
socket to the used local IPv4/6 address.localPort attribute of
socket to the used local source port.readyState attribute of
socket to "open".bufferedAmount attribute of
socket to 0.connectedSocket attribute of the
ConnectEvent object to
socket.
connect with
the newly created ConnectEvent instance at the
TCPServerSocket object.
Upon a new connection attempt to the TCP server socket that can not be served, e.g. due to max number of open connections, the user agent MUST run the following steps:
ErrorEvent.
error.name attribute of the
ErrorEvent object to
"NetworkError".
error with
the newly created ErrorEvent instance at the
TCPServerSocket object.
The following are the event handlers (and their
corresponding event handler event types) that MUST be supported as attributes
by the TCPServerSocket object.
| event handler | event name |
|---|---|
onconnect |
connect |
onerror |
error |
The connect event SHALL implement the ConnectEvent interface.
The error event SHALL implement the ErrorEvent interface.
UDPMessageEventThe UDPMessageEvent interface represents
events related to received UDP data. This interface extends the
MessageEvent interface, [POSTMSG]
The event's data attribute is intialized to a new read-only ArrayBuffer object whose contents are the recieved UDP data, [TYPED-ARRAYS]
[NoInterfaceObject]
interface UDPMessageEvent : MessageEvent {
readonly attribute DOMString remoteAddress;
readonly attribute unsigned short remotePort;
};
remoteAddress of type DOMString, readonlyremotePort of type unsigned short, readonlyConnectEventThe ConnectEvent interface represents
events related to accepted connections to a TCP server
socket.
[NoInterfaceObject]
interface ConnectEvent : Event {
readonly attribute TCPSocket connectedSocket;
};
connectedSocket of type TCPSocket, readonlyErrorEventThe ErrorEvent interface represents
events related to TCP connection errors.
[NoInterfaceObject]
interface ErrorEvent : Event {
readonly attribute DOMError error;
};
error of type
DOMError,
readonlyUDPOptionsStates the options for the UDPSocket. An instance of this
dictionary can optionally be used in the constructor of the
UDPSocket object, where all fields
are optional.
dictionary UDPOptions {
DOMString localAddress;
unsigned short localPort;
DOMString remoteAddress;
unsigned short remotePort;
boolean addressReuse;
boolean loopback;
};
UDPOptions
MembersaddressReuse of type booleantrue allows the socket to be bound to an
address that is already in use. Default is
true.localAddress of type DOMStringlocalPort
of type unsigned
shortloopback of
type booleantrue means that data you send is looped
back to your host. Default is false.remoteAddress of type DOMStringremotePort
of type unsigned
shortDo we need secure transport for UDP sockets??
TCPOptionsStates the options for the TCPSocket. An instance of this
dictionary can optionally be used in the constructor of the
TCPSocket object, where all fields
are optional.
dictionary TCPOptions {
DOMString localAddress;
unsigned short localPort;
boolean useSecureTransport;
};
TCPOptions
MemberslocalAddress of type DOMStringlocalPort
of type unsigned
shortuseSecureTransport of type booleantrue if socket uses SSL or TLS. Default is
false.Not sure if applications need to be able to bind the TCP Socket to local address/port?
Use of secure transport needs more investigation
TCPServerOptionsStates the options for the TCPServerSocket. An instance of this dictionary can optionally be used in the constructor of the TCPServerSocket object, where all fields are optional.
dictionary TCPServerOptions {
DOMString localAddress;
unsigned short localPort;
boolean useSecureTransport;
};
TCPServerOptions
MemberslocalAddress of type DOMStringlocalPort of type unsigned shortuseSecureTransport of type booleantrue if socket uses SSL or TLS. Default is
false.Use of secure transport needs more investigation
enum ReadyState {
"connecting",
"open",
"closing",
"closed",
"halfclosed"
};
| Enumeration description | |
|---|---|
connecting |
The TCP connection has not yet been established. |
open |
The TCP connection is established and communication is possible. |
closing |
The TCP connection is going through the closing handshake, or the close() method has been invoked. |
closed |
The TCP connection has been closed or could not be opened. |
halfclosed |
The TCP connection has been "halfclosed", which means that it is not possible to send data but it is still possible to received. |
Many thanks to Robin Berjon for making our lives so much easier with his cool tool.