WebSocketConnection
A API da classe WebSocketConnection
permite que você gerencie conexões WebSocket, uma vez estabelecida usando a classe WebSocketServer
.
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 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â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.