A WebSocket object that follows the browser standard. For detailed information about the API please read the WebSocket specification.
A WebSocket object can be constructed with NetworkDevice.createWebSocket.
Summary
Sends a text message.
Syntax
var message = "Hello World!";
websocket.send(message);
Summary
Closes the connection and prepares the WebSocket to be released.
Syntax
websocket.close();
Summary
Releases the WebSocket resources; the object will be invalid after the method is called.
Syntax
websocket.destroy();
Summary
The state of the WebSocket connection. All the possible values are properties on the WebSocket object:
Syntax
if (websocket.readyState === websocket.OPEN)
{
// Connection is ready for sending data
}
else if (websocket.readyState === websocket.CLOSED)
{
// Connection was closed
}
Note
Read Only
Summary
The callback that will be executed when the connection is established successfully.
Syntax
websocket.onopen = function connectionOpened() {
websocket.send("Hello World!");
};
Summary
The callback that will be executed when a new message arrives.
Syntax
websocket.onmessage = function messageReceived(message) {
window.alert("Message from server: " + message.data);
};
Summary
The callback that will be executed when the connection breaks.
Syntax
websocket.onerror = function connectionError() {
window.alert("Connection broken!");
websocket.onopen = null;
websocket.onerror = null;
websocket.onclose = null;
websocket.onmessage = null;
websocket = null;
};
Summary
The callback that will be executed when the connection is closed.
Syntax
websocket.onclose = function connectionOpened() {
window.alert("Connection closed!");
websocket.onopen = null;
websocket.onerror = null;
websocket.onclose = null;
websocket.onmessage = null;
websocket = null;
};