class HTTP::WebSocket
Defined in:
http/web_socket.crClass Method Summary
-
.new(uri : URI | String)
Opens a new websocket using the information provided by the URI.
-
.new(host : String, path : String, port = nil, ssl = false)
Opens a new websocket to the target host.
Instance Method Summary
- #close(message = nil)
- #on_close(&on_close : String -> )
- #on_message(&on_message : String -> )
- #run
- #send(message)
- #stream(binary = true, frame_size = 1024, &block)
Instance methods inherited from class Reference
==(other)==(other : self) ==, hash hash, inspect(io : IO) : Nil inspect, object_id : UInt64 object_id, same?(other : Reference)
same?(other : Nil) same?, to_s(io : IO) : Nil to_s
Instance methods inherited from class Object
!=(other)
!=,
!~(other)
!~,
==(other)
==,
===(other)===(other : YAML::Any)
===(other : JSON::Any) ===, =~(other) =~, class class, clone clone, crystal_type_id crystal_type_id, dup dup, hash hash, inspect
inspect(io : IO) inspect, itself itself, not_nil! not_nil!, tap(&block) tap, to_json to_json, to_pretty_json(io : IO)
to_pretty_json to_pretty_json, to_s
to_s(io : IO) to_s, to_yaml(io : IO)
to_yaml to_yaml, try(&block) try
Class methods inherited from class Object
==(other : Class)
==,
===(other)
===,
cast(other) : self
cast,
from_json(string_or_io) : self
from_json,
from_yaml(string : String) : self
from_yaml,
hash
hash,
inspect(io)
inspect,
name : String
name,
to_s(io)
to_s,
|(other : U.class)
|
Class Method Detail
Opens a new websocket using the information provided by the URI. This will also handle the handshake and will raise an exception if the handshake did not complete successfully. This method will also raise an exception if the URI is missing the host and/or the path.
Please note that the scheme will only be used to identify if SSL should be used or not. Therefore, schemes
apart from wss
and https
will be treated as the default which is ws
.
WebSocket.new(URI.parse("ws://websocket.example.com/chat")) # Creates a new WebSocket to `websocket.example.com`
WebSocket.new(URI.parse("wss://websocket.example.com/chat")) # Creates a new WebSocket with SSL to `websocket.example.com`
WebSocket.new(URI.parse("http://websocket.example.com:8080/chat")) # Creates a new WebSocket to `websocket.example.com` on port `8080`
Opens a new websocket to the target host. This will also handle the handshake and will raise an exception if the handshake did not complete successfully.
WebSocket.new("websocket.example.com", "/chat") # Creates a new WebSocket to `websocket.example.com`
WebSocket.new("websocket.example.com", "/chat", ssl = true) # Creates a new WebSocket with SSL to `ẁebsocket.example.com`