Dart API Referencedart:htmlWebSocket

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

EventTarget

Constructors

Code new WebSocket(String url) #

WebSocket(String url);

Static Fields

Code final int CLOSED #

static final int CLOSED = 3;

Code final int CLOSING #

static final int CLOSING = 2;

Code final int CONNECTING #

static final int CONNECTING = 0;

Code final int OPEN #

static final int OPEN = 1;

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 6.0 note
(Firefox 6.0 / Thunderbird 6.0 / SeaMonkey 2.3)

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 bool $dom_dispatchEvent(Event evt) #

bool $dom_dispatchEvent(Event evt);

Code void $dom_removeEventListener(String type, EventListener listener, [bool useCapture]) #

void $dom_removeEventListener(String type, EventListener listener, [bool useCapture]);

Fields

Code final String URL #

final String URL;

Code String binaryType #

A string indicating the type of binary data being transmitted by the connection. This should be either "blob" if DOM Blob  objects are being used or "arraybuffer" if ArrayBuffer objects are being used.
String binaryType;

Code final int bufferedAmount #

The number of bytes of data that have been queued using calls to but not yet transmitted to the network. This value does not reset to zero when the connection is closed; if you keep calling , this will continue to climb. Read only.
final int bufferedAmount;

Code final String extensions #

The extensions selected by the server. This is currently only the empty string or a list of extensions as negotiated by the connection.
final String extensions;

Code final String protocol #

A string indicating the name of the sub-protocol the server selected; this will be one of the strings specified in the protocols parameter when creating the WebSocket object.
final String protocol;

Code final int readyState #

The current state of the connection; this is one of the Ready state constants. Read only.
final int readyState;

Code final String url #

The URL as resolved by the constructor. This is always an absolute URL. Read only.
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.