WebSocket Interface
This is an experimental feature
Because this feature is still in development in some browsers, check the compatibility table for the proper prefixes to use in various browsers.
The WebSocket
object provides the API for creating and managing a WebSocket connection to a server, as well as for sending and receiving data on the connection.
Extends
Constructors
Static Fields
Methods
Code void close([int code, String reason]) #
Closes the WebSocket connection or connection attempt, if any. If the connection is already CLOSED
, this method does nothing.
Parameters
code
Optional- A numeric value indicating the status code explaining why the connection is being closed. If this parameter is not specified, a default value of 1000 (indicating a normal "transaction complete" closure) is assumed. See the list of status codes on the
CloseEvent
page for permitted values. reason
Optional- A human-readable string explaining why the connection is closing. This string must be no longer than 123 UTF-8 characters.
Exceptions thrown
INVALID_ACCESS_ERR
- An invalid
code
was specified. SYNTAX_ERR
- The
reason
string is too long or contains unpaired surrogates.
void close([int code, String reason]);
Code WebSocketEvents get on() #
WebSocketEvents get on();
Code bool send(String data) #
Transmits data to the server over the WebSocket connection.
Parameters
data
- A text string to send to the server.
Exceptions thrown
INVALID_STATE_ERR
- The connection is not currently
OPEN
. SYNTAX_ERR
- The data is a string that has unpaired surrogates.
Remarks
Gecko's implementation of the send()
method differs somewhat from the specification in Gecko 6.0; Gecko returns a boolean
indicating whether or not the connection is still open (and, by extension, that the data was successfully queued or transmitted); this is corrected in Gecko 8.0 (Firefox 8.0 / Thunderbird 8.0 / SeaMonkey 2.5)
. In addition, at this time, Gecko does not support ArrayBuffer
or Blob
data types.
bool send(String data);
Code void $dom_addEventListener(String type, EventListener listener, [bool useCapture]) #
void $dom_addEventListener(String type, EventListener listener, [bool useCapture]);
Code void $dom_removeEventListener(String type, EventListener listener, [bool useCapture]) #
void $dom_removeEventListener(String type, EventListener listener, [bool useCapture]);
Fields
Code String binaryType #
Blob
objects are being used or "arraybuffer" if ArrayBuffer
objects are being used.
String binaryType;
Code final int bufferedAmount #
final int bufferedAmount;
Code final String extensions #
final String extensions;
Code final String protocol #
protocols
parameter when creating the WebSocket object.
final String protocol;
Code final int readyState #
final int readyState;
Code final String url #
final String url;
This page includes content from the Mozilla Foundation that is graciously licensed under a Creative Commons: Attribution-Sharealike license. Mozilla has no other association with Dart or dartlang.org. We encourage you to improve the web by contributing to The Mozilla Developer Network.