Class: Ronin::Support::Web::WebSocket::Server::Client

Inherits:
Ronin::Support::Web::WebSocket::Socket show all
Defined in:
lib/ronin/support/web/websocket/server.rb

Overview

Represents a WebSocket client connected to the Websocket server.

Instance Attribute Summary

Attributes inherited from Ronin::Support::Web::WebSocket::Socket

#handshake, #socket

Instance Method Summary collapse

Methods inherited from Ronin::Support::Web::WebSocket::Socket

#close, #closed?, #handshake_finished?, #handshake_valid?, #recv, #recv_frame, #send, #send_frame

Constructor Details

#initialize(url, socket) ⇒ Client

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initializes a WebSocket server client.

Parameters:

  • url (URI::WS, URI::WSS)

    The WebSocket server's ws:// or wss:// URL.

  • socket (TCPSocket, OpenSSL::SSL::SSLSocket)

    The client's connection socket.



175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/ronin/support/web/websocket/server.rb', line 175

def initialize(url,socket)
  super()

  @url    = url
  @socket = socket

  receive_handshake!

  set_frame_classes(
    ::WebSocket::Frame::Incoming::Server,
    ::WebSocket::Frame::Outgoing::Server
  )
end

Instance Method Details

#receive_handshake!(**kwargs) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Receives the WebSocket handshake.



194
195
196
197
198
199
200
201
202
203
204
# File 'lib/ronin/support/web/websocket/server.rb', line 194

def receive_handshake!(**kwargs)
  @handshake = ::WebSocket::Handshake::Server.new(
    url: @url.to_s, **kwargs
  )

  @handshake << @socket.readpartial(1024) until @handshake.finished?

  if @handshake.valid?
    @socket.write(@handshake)
  end
end