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.
Historia
Lanzamiento | Modificaciones |
---|---|
20 | Añadidos |
Objeto WebSocketConnection
A WebSocketConnection
object is automatically created when the WSHandler.onConnection
callback function of the WebSocketServer object returns a connectionHandler
object.
Los objetos WebSocketConnection ofrecen las siguientes propiedades y funciones:
.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
Descripción
The .handler
property contains the accessor that gets the connectionHandler
object used to initiate the connection.
.id
.id : Integer
Descripción
The .id
property contains the unique identifier of the connection.
Esta propiedad es de sólo lectura.
.send()
.send( message : Text )
.send( message : Blob )
.send( message : Object )
Parámetros | Tipo | Descripción | |
---|---|---|---|
message | Text / Blob / Object | -> | El mensaje a enviar |
Descripción
The .send()
function sends a message to the client.
The following contents are sent depending on the message type:
Tipo | Contenido |
---|---|
Text | Texto en UTF-8 |
Blob | Datos binarios |
Object | Text in JSON UTF-8 (same result as with JSON Stringify ) |
.status
.status : Text
Descripción
The .status
property contains the connection status (can be "Closing", "Closed" or "Connected").
Esta propiedad es de sólo lectura.
.terminate()
.terminate( { code : Integer ; message : Text } )
Parámetros | Tipo | Descripción | |
---|---|---|---|
code | Integer | -> | Error code sent to the client (must be > 3000, otherwise the message is not sent) |
message | Text | -> | Mensaje de error enviado al cliente |
Descripción
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
Descripción
The .wss
property contains the WebSocketServer
parent object of the connection.
Esta propiedad es de sólo lectura.