Class: Ronin::Support::Web::WebSocket::Socket Abstract Private

Inherits:
Object
  • Object
show all
Defined in:
lib/ronin/support/web/websocket/socket.rb

Overview

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

This class is abstract.

Base class for all WebSockets.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#handshake::WebSocket::Handshake::Client, WebSocket::Handshake::Server (readonly)

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.

The WebSocket handshake information.

Returns:

  • (::WebSocket::Handshake::Client, WebSocket::Handshake::Server)


44
45
46
# File 'lib/ronin/support/web/websocket/socket.rb', line 44

def handshake
  @handshake
end

#socketTCPSocket, OpenSSL::SSL::SSLSocket (readonly)

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.

The underlying socket.

Returns:

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


39
40
41
# File 'lib/ronin/support/web/websocket/socket.rb', line 39

def socket
  @socket
end

Instance Method Details

#closeObject

Closes the socket.



148
149
150
# File 'lib/ronin/support/web/websocket/socket.rb', line 148

def close
  @socket.close
end

#closed?Boolean

Determines if the socket is closed.

Returns:

  • (Boolean)


159
160
161
# File 'lib/ronin/support/web/websocket/socket.rb', line 159

def closed?
  @socket.closed?
end

#handshake_finished?Boolean

Indicates whether the handshake has finished.

Returns:

  • (Boolean)


53
54
55
# File 'lib/ronin/support/web/websocket/socket.rb', line 53

def handshake_finished?
  @handshake.finished?
end

#handshake_valid?Boolean

Indicates whether the handshake was valid.

Returns:

  • (Boolean)


64
65
66
# File 'lib/ronin/support/web/websocket/socket.rb', line 64

def handshake_valid?
  @handshake.valid?
end

#recvString?

Receives a data frame.

Returns:

  • (String, nil)


138
139
140
141
# File 'lib/ronin/support/web/websocket/socket.rb', line 138

def recv
  data = recv_frame.data
  data unless data.empty?
end

#recv_frameWebSocket::Frame::Incoming::Client, WebSocket::Frame::Incoming::Server

Receives a data frame from the WebSocket.

The received websocket data frame.

Returns:

  • (WebSocket::Frame::Incoming::Client, WebSocket::Frame::Incoming::Server)


118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/ronin/support/web/websocket/socket.rb', line 118

def recv_frame
  frame = @incoming_frame_class.new(version: @handshake.version)

  begin
    # read data into the input frame
    frame << @socket.readpartial(1024)
  rescue EOFError
    return nil
  end

  return frame.next
end

#send(data, **kwargs) ⇒ Object

Sends a data frame.

Parameters:

  • data (#to_s)

    The data to send.

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments for #send_frame.

Options Hash (**kwargs):

  • :type (:text, :binary, :ping, :pong, :close) — default: :text

    The data frame type.

See Also:



105
106
107
# File 'lib/ronin/support/web/websocket/socket.rb', line 105

def send(data,**kwargs)
  send_frame(data,**kwargs)
end

#send_frame(data, type: :text) ⇒ Object

Sends a data frame.

Parameters:

  • data (#to_s)

    The data to send.

  • type (:text, :binary, :ping, :pong, :close) (defaults to: :text)

    The data frame type.



79
80
81
82
83
84
85
86
87
# File 'lib/ronin/support/web/websocket/socket.rb', line 79

def send_frame(data, type: :text)
  outgoing_frame = @outgoing_frame_class.new(
                     version: @handshake.version,
                     data:    data,
                     type:    type
                   )

  @socket.write(outgoing_frame.to_s)
end