Class: Ronin::Support::Web::WebSocket::Socket Abstract Private
- Inherits:
-
Object
- Object
- Ronin::Support::Web::WebSocket::Socket
- 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.
Base class for all WebSockets.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#handshake ⇒ ::WebSocket::Handshake::Client, WebSocket::Handshake::Server
readonly
private
The WebSocket handshake information.
-
#socket ⇒ TCPSocket, OpenSSL::SSL::SSLSocket
readonly
private
The underlying socket.
Instance Method Summary collapse
-
#close ⇒ Object
Closes the socket.
-
#closed? ⇒ Boolean
Determines if the socket is closed.
-
#handshake_finished? ⇒ Boolean
Indicates whether the handshake has finished.
-
#handshake_valid? ⇒ Boolean
Indicates whether the handshake was valid.
-
#recv ⇒ String?
Receives a data frame.
-
#recv_frame ⇒ WebSocket::Frame::Incoming::Client, WebSocket::Frame::Incoming::Server
Receives a data frame from the WebSocket.
-
#send(data, **kwargs) ⇒ Object
Sends a data frame.
-
#send_frame(data, type: :text) ⇒ Object
Sends a data frame.
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.
44 45 46 |
# File 'lib/ronin/support/web/websocket/socket.rb', line 44 def handshake @handshake end |
#socket ⇒ TCPSocket, 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.
39 40 41 |
# File 'lib/ronin/support/web/websocket/socket.rb', line 39 def socket @socket end |
Instance Method Details
#close ⇒ Object
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.
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.
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.
64 65 66 |
# File 'lib/ronin/support/web/websocket/socket.rb', line 64 def handshake_valid? @handshake.valid? end |
#recv ⇒ String?
Receives a data frame.
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_frame ⇒ WebSocket::Frame::Incoming::Client, WebSocket::Frame::Incoming::Server
Receives a data frame from the WebSocket.
The received websocket data frame.
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.
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.
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 |