HTTP::WebSocket

class HTTP::WebSocket

Defined in:

http/web_socket.cr

Class Method Summary

Instance Method Summary

Class Method Detail

def self.new(host : String, path : String, port = nil, tls = false)Source

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.

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`

def self.new(uri : URI | String)Source

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.

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`

Instance Method Detail

def close(message = nil)Source

def closed? : BoolSource

def on_binary(&on_binary : Bytes -> )Source

def on_close(&on_close : String -> )Source

def on_message(&on_message : String -> )Source

def on_ping(&on_ping : String -> )Source

def on_pong(&on_pong : String -> )Source

def ping(message = nil)Source

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.

def pong(message = nil)Source

Server can send an unsolicited PONG frame which the client should not respond to.

See #ping.

def runSource

def send(message)Source

def stream(binary = true, frame_size = 1024, &block)Source

© 2012–2017 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/0.22.0/HTTP/WebSocket.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部