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.
Historique
Release | Modifications |
---|---|
20 | Ajout |
Objet WebSocketConnection
A WebSocketConnection
object is automatically created when the WSHandler.onConnection
callback function of the WebSocketServer object returns a connectionHandler
object.
Les objets WebSocketConnection offrent les propriétés et fonctions suivantes :
.handler : Object the accessor that gets the connectionHandler object used to initiate the connection |
.id : Integer the unique identifier of the connection |
.send( message : Text ) .send( message : Blob ) .send( message : Object ) sends a message to the client |
.status : Text the connection status (can be "Closing", "Closed" or "Connected") |
.terminate( { code : Integer ; message : Text } ) forces the connection to close |
.wss : 4D.WebSocketServer the WebSocketServer parent object of the connection |
.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.
Cette propriété est en lecture seule.
.send()
.send( message : Text )
.send( message : Blob )
.send( message : Object )
Paramètres | Type | Description | |
---|---|---|---|
message | Text / Blob / Object | -> | Le message à envoyer |
Description
The .send()
function sends a message to the client.
The following contents are sent depending on the message type:
Type | Contenu |
---|---|
Text | Texte en UTF-8 |
Blob | Données binaires |
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").
Cette propriété est en lecture seule.
.terminate()
.terminate( { code : Integer ; message : Text } )
Paramètres | Type | Description | |
---|---|---|---|
code | Integer | -> | Error code sent to the client (must be > 3000, otherwise the message is not sent) |
message | Text | -> | Message d'erreur envoyé au 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.
Cette propriété est en lecture seule.