Saltar para o conteúdo principal
Versão: 20 R8

WebSocketConnection

A API da classe WebSocketConnection permite que você gerencie conexões WebSocket, uma vez estabelecida usando a classe WebSocketServer.

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
o acessório que obtém o objeto connectionHandler usado para iniciar a conexão
.id : Integer
o identificador único da conexão
.send( message : Text )
.send( message : Blob )
.send( message : Object )

envia uma message para o cliente
.status : Text
the connection status (can be "Closing", "Closed" or "Connected")
.terminate( { code : Integer ; message : Text } )
força a conexão a fechar
.wss : 4D.WebSocketServer
the WebSocketServer parent object of the connection

.handler

.handler : Object

Descrição

A propriedade .handler contém o acessório que obtém o objeto connectionHandler usado para iniciar a conexão.

.id

.id : Integer

Descrição

A propriedade .id contém o identificador único da conexão.

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

A função .send() envia uma message para o cliente.

Os conteúdos seguintes são enviados em função do tipo de message:

TipoConteúdo
TextTexto em UTF-8
BlobDados binários
ObjectTexto em JSON UTF-8 (o mesmo resultado que com 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

A função .terminate() força a conexão a fechar.

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.