Last data update: 2014.03.03

R: WebSocket object
WebSocket-classR Documentation

WebSocket object

Description

An object that represents a single WebSocket connection. The object can be used to send messages and close the connection, and to receive notifications when messages are received or the connection is closed.

Arguments

...

For internal use only.

Details

WebSocket objects should never be created directly. They are obtained by passing an onWSOpen function to startServer.

Fields

request

The Rook request environment that opened the connection. This can be used to inspect HTTP headers, for example.

Methods

onMessage(func)

Registers a callback function that will be invoked whenever a message is received on this connection. The callback function will be invoked with two arguments. The first argument is TRUE if the message is binary and FALSE if it is text. The second argument is either a raw vector (if the message is binary) or a character vector.

onClose(func)

Registers a callback function that will be invoked when the connection is closed.

send(message)

Begins sending the given message over the websocket. The message must be either a raw vector, or a single-element character vector that is encoded in UTF-8.

close()

Closes the websocket connection.

Results