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.
História
Release | Mudanças |
---|---|
20 | Adicionado |
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 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
The .handler
property contains the accessor that gets the connectionHandler
object used to initiate the connection.
.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âmetro | Tipo | Descrição | |
---|---|---|---|
message | Text / 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:
Tipo | Conteúdo |
---|---|
Text | Texto em UTF-8 |
Blob | Dados binários |
Object | Texto 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âmetro | Tipo | Descrição | |
---|---|---|---|
code | Integer | -> | Error code sent to the client (must be > 3000, otherwise the message is not sent) |
message | Text | -> | 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.