Dart API Referencedart:ioWebSocket

WebSocket abstract class

Alternative web socket client interface. This interface is compliant with the W3C browser API for web sockets specified in http://dev.w3.org/html5/websockets/.

abstract class WebSocket {
  /**
   * Possible states of the connection.
   */
  static const int CONNECTING = 0;
  static const int OPEN = 1;
  static const int CLOSING = 2;
  static const int CLOSED = 3;

  /**
   * Create a new web socket connection. The URL supplied in [url]
   * must use the scheme [:ws:]. The [protocols] argument is either a
   * [:String:] or [:List<String>:] specifying the subprotocols the
   * client is willing to speak.
   */
  factory WebSocket(String url, [protocols]) => new _WebSocket(url, protocols);

  /**
   * Returns the current state of the connection.
   */
  int get readyState;

  /**
   * Returns the number of bytes currently buffered for transmission.
   */
  int get bufferedAmount;

  /**
   * Sets the callback to be called when a web socket connection has
   * been established.
   */
  void set onopen(void callback());

  /**
   * Sets the callback to be called when the web socket connection
   * encountered an error.
   */
  void set onerror(void callback(e));

  /**
   * Sets the callback to be called when the web socket connection is
   * closed.
   */
  void set onclose(void callback(CloseEvent event));

  /**
   * The extensions property is initially the empty string. After the
   * web socket connection is established this string reflects the
   * extensions used by the server.
   */
  String get extensions;

  /**
   * The protocol property is initially the empty string. After the
   * web socket connection is established the value is the subprotocol
   * selected by the server. If no subprotocol is negotiated the
   * value will remain [:null:].
   */
  String get protocol;

  /**
   * Closes the web socket connection.
   */
  void close(int code, String reason);

  /**
   * Sets the callback to be called when a message have been
   * received.
   */
  void set onmessage(void callback(MessageEvent event));

  /**
   * Sends data on the web socket connection. The data in [data] must
   * be either a [:String:] or [:List<int>:] holding bytes.
   */
  void send(data);
}

Static Properties

const int CLOSED #

static const int CLOSED = 3;

const int CLOSING #

static const int CLOSING = 2;

const int CONNECTING #

Possible states of the connection.

static const int CONNECTING = 0;

const int OPEN #

static const int OPEN = 1;

Constructors

factory WebSocket(String url, [protocols]) #

Create a new web socket connection. The URL supplied in url must use the scheme ws. The protocols argument is either a String or List<String> specifying the subprotocols the client is willing to speak.

factory WebSocket(String url, [protocols]) => new _WebSocket(url, protocols);

Properties

final int bufferedAmount #

Returns the number of bytes currently buffered for transmission.

int get bufferedAmount;

final String extensions #

The extensions property is initially the empty string. After the web socket connection is established this string reflects the extensions used by the server.

String get extensions;

void set onclose(void callback(CloseEvent event)) #

Sets the callback to be called when the web socket connection is closed.

void set onclose(void callback(CloseEvent event));

void set onerror(void callback(e)) #

Sets the callback to be called when the web socket connection encountered an error.

void set onerror(void callback(e));

void set onmessage(void callback(MessageEvent event)) #

Sets the callback to be called when a message have been received.

void set onmessage(void callback(MessageEvent event));

void set onopen(void callback()) #

Sets the callback to be called when a web socket connection has been established.

void set onopen(void callback());

final String protocol #

The protocol property is initially the empty string. After the web socket connection is established the value is the subprotocol selected by the server. If no subprotocol is negotiated the value will remain null.

String get protocol;

final int readyState #

Returns the current state of the connection.

int get readyState;

Methods

void close(int code, String reason) #

Closes the web socket connection.

void close(int code, String reason);

void send(data) #

Sends data on the web socket connection. The data in data must be either a String or List<int> holding bytes.

void send(data);