abstract class Azu::Channel
- Azu::Channel
- Reference
- Object
Overview
A channel encapsulates a logical unit of work similar to an Endpoint.
Channels manage WebSocket connections, handling multiple instances where a single client may have multiple WebSocket connections open to the application.
Each channel can broadcast to multiple connected clients.
To set up a WebSocket route in your routing service:
ExampleApp.router do
ws "/hi", ExampleApp::ExampleChannel
end
Pings and Pongs: The Heartbeat of WebSockets
After the handshake, either the client or the server can send a ping to the other party. Upon receiving a ping, the recipient must promptly send back a pong. This mechanism ensures that the client remains connected.
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)
Handles the incoming WebSocket HTTP request
-
#on_binary(binary : Bytes)
Invoked when a binary message is received
-
#on_close(code : HTTP::WebSocket::CloseCode | Nil, message : String | Nil)
Invoked when the connection is closed
-
#on_connect
Invoked when a connection is established
-
#on_message(message : String)
Invoked when a text message is received
-
#on_ping(message : String)
Invoked when a ping frame is received
-
#on_pong(message : String)
Invoked when a pong frame is received
- #socket : HTTP::WebSocket
- #socket? : HTTP::WebSocket | Nil
Constructor Detail
Class Method Detail
Instance Method Detail
Invoked when the connection is closed