Opens a new websocket to the target host.
Opens a new websocket using the information provided by the URI.
DEPRECATED Use WebSocket#close(code, message) instead
It's possible to send a PING frame, which the client must respond to with a PONG, or the server can send an unsolicited PONG frame which the client should not respond to.
Server can send an unsolicited PONG frame which the client should not respond to.
Reference
Reference
Object
Object
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.
require "http/web_socket" HTTP::WebSocket.new("websocket.example.com", "/chat") # Creates a new WebSocket to `websocket.example.com` HTTP::WebSocket.new("websocket.example.com", "/chat", tls: true) # Creates a new WebSocket with TLS to `ẁebsocket.example.com`
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 TLS should be used or not. Therefore, schemes apart from wss
and https
will be treated as the default which is ws
.
require "http/web_socket" HTTP::WebSocket.new(URI.parse("ws://websocket.example.com/chat")) # Creates a new WebSocket to `websocket.example.com` HTTP::WebSocket.new(URI.parse("wss://websocket.example.com/chat")) # Creates a new WebSocket with TLS to `websocket.example.com` HTTP::WebSocket.new(URI.parse("http://websocket.example.com:8080/chat")) # Creates a new WebSocket to `websocket.example.com` on port `8080` HTTP::WebSocket.new(URI.parse("ws://websocket.example.com/chat"), # Creates a new WebSocket to `websocket.example.com` with an Authorization header HTTP::Headers{"Authorization" => "Bearer authtoken"})
DEPRECATED Use WebSocket#close(code, message) instead
It's possible to send a PING frame, which the client must respond to with a PONG, or the server can send an unsolicited PONG frame which the client should not respond to.
See #pong
.
Server can send an unsolicited PONG frame which the client should not respond to.
See #ping
.
© 2012–2020 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/0.35.1/HTTP/WebSocket.html