WebSocketConnection
The WebSocketConnection class API allows you to handle WebSocket connections, once established using the WebSocketServer class.
For an overview and some examples of the WebSocket server implementation in 4D, please refer to the WebSocketServer class.
History
| Release | Changes | 
|---|---|
| 20 | Added | 
WebSocketConnection object
A WebSocketConnection object is automatically created when the WSHandler.onConnection callback function of the WebSocketServer object returns a connectionHandler object.
WebSocketConnection objects provide the following properties and functions:
.handler
.handler* : Object
Description
The .handler property contains the accessor that gets the connectionHandler object used to initiate the connection.
.id
.id* : Integer
Description
The .id property contains the unique identifier of the connection.
This property is read-only.
.send()
.send*( message : Text )
.send( message : Blob )
.send( message : Object )
| Parameter | Type | Description | |
|---|---|---|---|
| message | Text / Blob / Object | -> | The message to send | 
Description
The .send() function sends a message to the client.
The following contents are sent depending on the message type:
| Type | Content | 
|---|---|
| Text | Text in UTF-8 | 
| Blob | Binary data | 
| Object | Text in JSON UTF-8 (same result as with JSON Stringify) | 
.status
.status* : Text
Description
The .status property contains the connection status (can be "Closing", "Closed" or  "Connected").
This property is read-only.
.terminate()
.terminate*( { code : Integer ; message : Text } )
| Parameter | Type | Description | |
|---|---|---|---|
| code | Integer | -> | Error code sent to the client (must be > 3000, otherwise the message is not sent) | 
| message | Text | -> | Error message sent to the client | 
Description
The .terminate() function forces the connection to close.
A code and message can be sent to the client during the closure to indicate the reason of the termination.
.wss
.wss* : 4D.WebSocketServer
Description
The .wss property contains the WebSocketServer parent object of the connection.
This property is read-only.