Dart API Referencedart:ioWebSocketClientConnection

WebSocketClientConnection abstract class

Client web socket connection.

abstract class WebSocketClientConnection {
  /**
   * Creates a new web socket client connection based on a HTTP client
   * connection. The HTTP client connection must be freshly opened.
   */
  factory WebSocketClientConnection(HttpClientConnection conn,
                                    [List<String> protocols]) {
    return new _WebSocketClientConnection(conn, protocols);
  }

  /**
   * Sets the callback to be called when the request object for the
   * opening handshake request is ready. This callback can be used if
   * one need to add additional headers to the opening handshake
   * request.
   */
  void set onRequest(void callback(HttpClientRequest request));

  /**
   * 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 a message have been
   * received. The type of [message] is either [:String:] or
   * [:List<int>:] depending on whether it is a text or binary
   * message. If the message is empty [message] will be [:null:].
   */
  void set onMessage(void callback(message));

  /**
   * Sets the callback to be called when the web socket connection is
   * closed. [status] indicate the reason for closing. For network
   * errors the value of [status] will be
   * WebSocketStatus.ABNORMAL_CLOSURE].
   */
  void set onClosed(void callback(int status, String reason));

  /**
   * Sets the callback to be called when the response object for the
   * opening handshake did not cause a web socket connection
   * upgrade. This will be called in case the response status code is
   * not 101 (Switching Protocols). If this callback is not set the
   * [:onError:] callback will be called if the server did not upgrade
   * the connection.
   */
  void set onNoUpgrade(void callback(HttpClientResponse response));

  /**
   * Sends a message. The [message] must be a [:String:] or a
   * [:List<int>:]. To send an empty message use either an empty
   * [:String:] or an empty [:List<int>:]. [:null:] cannot be used.
   */
  send(message);

  /**
   * Close the web socket connection. The default value for [status]
   * and [reason] are [:null:].
   */
  close([int status, String reason]);

  /**
   * WebSocketClientConnection is hashable.
   */
  int get hashCode;
}

Constructors

factory WebSocketClientConnection(HttpClientConnection conn, [List<String> protocols]) #

Creates a new web socket client connection based on a HTTP client connection. The HTTP client connection must be freshly opened.

factory WebSocketClientConnection(HttpClientConnection conn,
                                  [List<String> protocols]) {
  return new _WebSocketClientConnection(conn, protocols);
}

Properties

final int hashCode #

WebSocketClientConnection is hashable.

int get hashCode;

void set onClosed(void callback(int status, String reason)) #

Sets the callback to be called when the web socket connection is closed. status indicate the reason for closing. For network errors the value of status will be WebSocketStatus.ABNORMAL_CLOSURE].

void set onClosed(void callback(int status, String reason));

void set onMessage(void callback(message)) #

Sets the callback to be called when a message have been received. The type of message is either String or List<int> depending on whether it is a text or binary message. If the message is empty message will be null.

void set onMessage(void callback(message));

void set onNoUpgrade(void callback(HttpClientResponse response)) #

Sets the callback to be called when the response object for the opening handshake did not cause a web socket connection upgrade. This will be called in case the response status code is not 101 (Switching Protocols). If this callback is not set the onError callback will be called if the server did not upgrade the connection.

void set onNoUpgrade(void callback(HttpClientResponse response));

void set onOpen(void callback()) #

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

void set onOpen(void callback());

void set onRequest(void callback(HttpClientRequest request)) #

Sets the callback to be called when the request object for the opening handshake request is ready. This callback can be used if one need to add additional headers to the opening handshake request.

void set onRequest(void callback(HttpClientRequest request));

Methods

close([int status, String reason]) #

Close the web socket connection. The default value for status and reason are null.

close([int status, String reason]);

send(message) #

Sends a message. The message must be a String or a List<int>. To send an empty message use either an empty String or an empty List<int>. null cannot be used.

send(message);