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
Instance methods
Sends a close frame, and closes the connection. The close frame may contain a body (message) that indicates the reason for closing.
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