Method: OpenC3::WebSocketClientStream#initialize

Defined in:
lib/openc3/streams/web_socket_client_stream.rb

#initialize(url, write_timeout, read_timeout, connect_timeout = 5.0) ⇒ WebSocketClientStream

Returns a new instance of WebSocketClientStream.

Parameters:

  • url (String)

    The host to connect to

  • write_timeout (Float)

    Seconds to wait before aborting writes

  • read_timeout (Float|nil)

    Seconds to wait before aborting reads. Pass nil to block until the read is complete.

  • connect_timeout (Float|nil) (defaults to: 5.0)

    Seconds to wait before aborting connect. Pass nil to block until the connection is complete.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/openc3/streams/web_socket_client_stream.rb', line 34

def initialize(url, write_timeout, read_timeout, connect_timeout = 5.0)
  @url = url
  @uri = URI.parse @url
  port = ((@uri.scheme == 'wss' or @uri.scheme == 'https') ? 443 : 80)
  port = @uri.port if @uri.port
  super(@uri.host, port, port, write_timeout, read_timeout, connect_timeout)
  if ['https', 'wss'].include? @uri.scheme
    socket = ::OpenSSL::SSL::SSLSocket.new(@write_socket)
    socket.sync_close = true
    socket.hostname = @uri.host
    @write_socket = socket
    @read_socket = socket
  end
  @headers = {}
end