Saltar al contenido principal
Versión: 20 R5

WebSocketConnection

La API de la clase WebSocketConnection te permite gestionar conexiones WebSocket, una vez establecidas usando la clase WebSocketServer.

info

For an overview and some examples of the WebSocket server implementation in 4D, please refer to the WebSocketServer class.

Historia
LanzamientoModificaciones
20Añ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
el identificador único de la conexión
.send( message : Text )
.send( message : Blob )
.send( message : Object )

sends a message to the client
.status : Text
el estado de la conexión (puede ser "Closing", "Closed" o "Connected")
.terminate( { code : Integer ; message : Text } )
fuerza el cierre de la conexión
.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

La propiedad .id contiene el identificador único de la conexión.

Esta propiedad es de sólo lectura.

.send()

.send( message : Text )
.send( message : Blob )
.send( message : Object )

ParámetrosTipoDescripción
messageText / Blob / Object->El mensaje a enviar

Descripción

The .send() function sends a message to the client.

Los siguientes contenidos se envían en función del tipo de message:

TipoContenido
TextTexto en UTF-8
BlobDatos binarios
ObjectTexto en JSON UTF-8 (mismo resultado que con JSON Stringify)

.status

.status : Text

Descripción

La propiedad .status contiene el estado de la conexión (puede ser "Closing", "Closed" o "Connected").

Esta propiedad es de sólo lectura.

.terminate()

.terminate( { code : Integer ; message : Text } )

ParámetrosTipoDescripción
codeInteger->Código de error enviado al cliente (debe ser > 3000, de lo contrario el mensaje no se envía)
messageText->Mensaje de error enviado al cliente

Descripción

La función .terminate() fuerza el cierre de la conexión.

Un code y un message pueden ser enviados al cliente durante el cierre para indicar la razón de la terminación.

.wss

.wss : 4D.WebSocketServer

Descripción

The .wss property contains the WebSocketServer parent object of the connection.

Esta propiedad es de sólo lectura.