class

Hop::WssBearer::BoundedWebSocket

Inherits HTTP::WebSocket < Reference < Object

Compatible with HTTP::WebSocket for callers, but owns the receive parser so a declared payload is checked before Bytes.new and fragmented totals are checked before each continuation body.

Constructors

new(io : IO, masked_out : Bool, expect_masked : Bool)
Source

Instance methods

close(code : HTTP::WebSocket::CloseCode | Int | Nil = nil, message = nil) : Nil

Sends a close frame, and closes the connection. The close frame may contain a body (message) that indicates the reason for closing.

Source
on_binary

Called when a binary message is received.

Source
on_close

Called when the connection is closed by the other party.

Source
run

Continuously receives messages and calls previously set callbacks until the websocket is closed. Ping and pong messages are automatically handled.

# Open websocket connection
ws = HTTP::WebSocket.new("websocket.example.com", "/chat")

# Set callback
ws.on_message do |msg|
  ws.send "response"
end

# Start infinite loop
ws.run
Source
send(message : Bytes) : Nil
Source