Description
Supported Script Types: Interface Scripts • Client Entity Scripts • Avatar Scripts • Server Entity Scripts • Assignment Client Scripts
Provides a bi-directional, event-driven communication session between the script and another WebSocket connection. It is a near-complete implementation of the WebSocket API described in the Mozilla docs: https://developer.mozilla.org/en-US/docs/Web/API/WebSocket.Create using new WebSocket(...)
in Interface, client entity, avatar, and server entity scripts, or the
WebSocketServer class in server entity and assignment client scripts.
Note: Does not support secure, wss:
protocol.
Properties
Name | Type | Summary |
---|---|---|
binaryType | string |
Not used. Default Value: "blob" |
bufferedAmount | number |
Not implemented. Read-only. Default Value: 0 |
extensions | string |
Not implemented. Read-only. Default Value: "" |
onopen | WebSocket~onOpenCallback |
Function called when the connection opens. |
onmessage | WebSocket~onMessageCallback |
Function called when a message is received. |
onerror | WebSocket~onErrorCallback |
Function called when an error occurs. |
onclose | WebSocket~onCloseCallback |
Function called when the connection closes. |
protocol | string |
Not implemented. Read-only. Default Value: "" |
readyState | WebSocket.ReadyState |
The state of the connection. Read-only. |
url | string |
The URL to connect to. Read-only. |
CONNECTING | WebSocket.ReadyState |
The connection is opening. Read-only. |
OPEN | WebSocket.ReadyState |
The connection is open. Read-only. |
CLOSING | WebSocket.ReadyState |
The connection is closing. Read-only. |
CLOSED | WebSocket.ReadyState |
The connection is closed. Read-only. |
Constructor | ||||||
---|---|---|---|---|---|---|
new WebSocket( urlOrWebSocket )
Parameters
|
Example
print("Create WebSocket");
var WEBSOCKET_PING_URL = "ws://echo.websocket.org";
var webSocket = new WebSocket(WEBSOCKET_PING_URL);
webSocket.onclose = function (data) {
print("WebSocket closed");
print("Ready state =", webSocket.readyState); // 3
};
webSocket.onmessage = function (data) {
print("Message received:", data.data);
print("Close WebSocket");
webSocket.close();
};
webSocket.onopen = function () {
print("WebSocket opened");
print("Ready state =", webSocket.readyState); // 1
print("Send a test message");
webSocket.send("Test message");
};
Methods
Name | Return Value | Summary |
---|---|---|
close
|
None |
Closes the connection. |
send
|
None |
Sends a message on the connection. |
Type Definitions
CloseCode Type: number |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
The reason why the connection was closed.
Method Details
|