WebSocketClientConnection Interface
Client web socket connection.
Extends
Constructors
Code new 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.
WebSocketClientConnection(HttpClientConnection conn, [List<String> protocols]);
Methods
Code close([int status, String reason]) #
Close the web socket connection. The default value for
status
and
reason are null
.
close([int status, String reason]);
Code void set onClosed(void callback(int status, String reason)) #
Sets the callback to be called when the web socket connection is closed.
void set onClosed(void callback(int status, String reason));
Code 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));
Code 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));
Code 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));
Code void set onOpen(void callback()) #
Sets the callback to be called when a web socket connection has been established.
void set onOpen(void callback());
Code 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));
Code 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);