INNER CODE UNIT · Ruby

WSClient

royshil/obs-backgroundremoval · scripts/ws_client.rb:11

class WSClient
  def connect(host, port)
    @seqnum = 0

    @socket = TCPSocket.new(host, port)
    key = Base64.strict_encode64(Random.bytes(16))

    handshake = [
      'GET / HTTP/1.1',
      "Host: #{host}:#{port}",
      'Upgrade: websocket',
      'Connection: Upgrade',
      "Sec-WebSocket-Key: #{key}",
      'Sec-WebSocket-Version: 13',
      '', ''
    ].join("\r\n")

    @socket.write(handshake)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…