abstract class Azu::Channel

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.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(socket : HTTP::WebSocket) #

[View source]

Class Method Detail

def self.ws(path : Router::Path) #

Registers a websocket route


[View source]

Instance Method Detail

def call(context : HTTP::Server::Context) #

Handler to execute the incomming websocket http request


[View source]
abstract def on_binary(binary) #

Invoked when the channel receives a binary message


[View source]
abstract def on_close(code : HTTP::WebSocket::CloseCode | Int | Nil = nil, message = nil) #

Invoked when the channel process is about to exit.


[View source]
abstract def on_connect #

On Connect event handler Invoked when incoming socket connection connects to the endpoint


[View source]
abstract def on_message(message) #

Invoked when the channel receives a message


[View source]
abstract def on_ping(message) #

Invoked when the client has requested a ping message

Pings have an opcode of 0x9


[View source]
abstract def on_pong(message) #

Invoked when the client has requested a pong message

Pongs have an opcode of 0xA


[View source]
def socket : HTTP::WebSocket #

[View source]
def socket? : HTTP::WebSocket | Nil #

[View source]