Saltar para o conteúdo principal
Versão: 20 R5 BETA

WebSocketConnection

The WebSocketConnection class API allows you to handle WebSocket connections, once established using the WebSocketServer class.

info

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

História
ReleaseMudanças
20Adicionado

Objecto WebSocketConnection

A WebSocketConnection object is automatically created when the WSHandler.onConnection callback function of the WebSocketServer object returns a connectionHandler object.

Os objectos Httprequest fornecem as seguintes propriedades e funções:

.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

Descrição

The .handler property contains the accessor that gets the connectionHandler object used to initiate the connection.

.id

.id : Integer

Descrição

The .id property contains the unique identifier of the connection.

Esta propriedade é só de leitura.

.send()

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

ParâmetroTipoDescrição
messageText / Blob / Object->A mensagem a enviar

Descrição

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

The following contents are sent depending on the message type:

TipoConteúdo
TextTexto em UTF-8
BlobDados binários
ObjectText in JSON UTF-8 (same result as with JSON Stringify)

.status

.status : Text

Descrição

The .status property contains the connection status (can be "Closing", "Closed" or "Connected").

Esta propriedade é só de leitura.

.terminate()

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

ParâmetroTipoDescrição
codeInteger->Error code sent to the client (must be > 3000, otherwise the message is not sent)
messageText->Mensagem de erro enviada ao cliente

Descrição

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

Descrição

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

Esta propriedade é só de leitura.