abstract class Azu::Channel
- Azu::Channel
- Reference
- Object
Overview
A channel encapsulates a logical unit of work similar to an Endpoint.
Channels are used for websocket connections that can handle multiple connections instances. A single client may have multiple WebSockets connections open to the application.
Each channel can in turn broadcast to multiple connected clients
You must setup a websocket route in your routing service
ExampleApp.router do
ws "/hi", ExampleApp::ExampleChannel
end
Pings and Pongs: The Heartbeat of WebSockets
At any point after the handshake, either the client or the server can choose to send a ping to the other party. When the ping is received, the recipient must send back a pong as soon as possible. You can use this to make sure that the client is still connected, for example.
Direct Known Subclasses
Defined in:
azu/channel.crConstructors
Class Method Summary
-
.ws(path : Router::Path)
Registers a websocket route
Instance Method Summary
-
#call(context : HTTP::Server::Context)
Handler to execute the incomming websocket http request
-
#on_binary(binary)
Invoked when the channel receives a binary message
-
#on_close(code : HTTP::WebSocket::CloseCode | Int | Nil = nil, message = nil)
Invoked when the channel process is about to exit.
-
#on_connect
On Connect event handler Invoked when incoming socket connection connects to the endpoint
-
#on_message(message)
Invoked when the channel receives a message
-
#on_ping(message)
Invoked when the client has requested a ping message
-
#on_pong(message)
Invoked when the client has requested a pong message
- #socket : HTTP::WebSocket
- #socket? : HTTP::WebSocket | Nil
Constructor Detail
Class Method Detail
Instance Method Detail
Invoked when the channel process is about to exit.
On Connect event handler Invoked when incoming socket connection connects to the endpoint
Invoked when the client has requested a ping message
Pings have an opcode of 0x9
Invoked when the client has requested a pong message
Pongs have an opcode of 0xA