Class: Ronin::Support::Web::WebSocket::Server
- Inherits:
-
Object
- Object
- Ronin::Support::Web::WebSocket::Server
- Includes:
- URLMethods
- Defined in:
- lib/ronin/support/web/websocket/server.rb
Overview
Represents a WebSocket server.
Defined Under Namespace
Classes: Client
Instance Attribute Summary collapse
-
#socket ⇒ TCPServer, OpenSSL::SSL::SSLServer
readonly
The underlying server socket.
Attributes included from URLMethods
Instance Method Summary collapse
-
#accept ⇒ Client
Accepts a new WebSocket connection.
-
#close ⇒ Object
Closes the WebSocket server's socket.
-
#closed? ⇒ Boolean
Determines if the WebSocket server is closed?.
-
#initialize(url, bind_host: nil, bind_port: nil, backlog: 5, ssl: {}) ⇒ Server
constructor
Initializes the WebSocket server.
-
#listen(backlog) ⇒ Object
Sets the connection backlog for the server socket.
Methods included from URLMethods
Constructor Details
#initialize(url, bind_host: nil, bind_port: nil, backlog: 5, ssl: {}) ⇒ Server
Initializes the WebSocket server.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/ronin/support/web/websocket/server.rb', line 91 def initialize(url, bind_host: nil, bind_port: nil, backlog: 5, ssl: {}) super(url) @bind_host = bind_host @bind_port = bind_port || @port @socket = case @url.scheme when 'ws' Support::Network::TCP.server( host: @bind_host, port: @bind_port, backlog: backlog ) when 'wss' Support::Network::SSL.server( host: @bind_host, port: @bind_port, backlog: backlog, **ssl ) else raise(ArgumentError,"unsupported websocket scheme: #{url}") end end |
Instance Attribute Details
#socket ⇒ TCPServer, OpenSSL::SSL::SSLServer (readonly)
The underlying server socket.
42 43 44 |
# File 'lib/ronin/support/web/websocket/server.rb', line 42 def socket @socket end |
Instance Method Details
#accept ⇒ Client
Accepts a new WebSocket connection.
135 136 137 |
# File 'lib/ronin/support/web/websocket/server.rb', line 135 def accept Client.new(@url,@socket.accept) end |
#close ⇒ Object
Closes the WebSocket server's socket.
144 145 146 |
# File 'lib/ronin/support/web/websocket/server.rb', line 144 def close @socket.close end |
#closed? ⇒ Boolean
Determines if the WebSocket server is closed?
155 156 157 |
# File 'lib/ronin/support/web/websocket/server.rb', line 155 def closed? @socket.closed? end |
#listen(backlog) ⇒ Object
Sets the connection backlog for the server socket.
125 126 127 |
# File 'lib/ronin/support/web/websocket/server.rb', line 125 def listen(backlog) @socket.listen(backlog) end |