Class: RubyHome::HAP::Server
- Inherits:
-
Object
- Object
- RubyHome::HAP::Server
- Defined in:
- lib/ruby_home/hap/server.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#socket_store ⇒ Object
readonly
Returns the value of attribute socket_store.
Instance Method Summary collapse
-
#initialize(host, port, socket_store) ⇒ Server
constructor
A new instance of Server.
- #run ⇒ Object
Constructor Details
#initialize(host, port, socket_store) ⇒ Server
Returns a new instance of Server.
4 5 6 7 8 9 |
# File 'lib/ruby_home/hap/server.rb', line 4 def initialize(host, port, socket_store) @port = port @host = host @socket_store = socket_store @selector = NIO::Selector.new end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
11 12 13 |
# File 'lib/ruby_home/hap/server.rb', line 11 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
11 12 13 |
# File 'lib/ruby_home/hap/server.rb', line 11 def port @port end |
#socket_store ⇒ Object (readonly)
Returns the value of attribute socket_store.
11 12 13 |
# File 'lib/ruby_home/hap/server.rb', line 11 def socket_store @socket_store end |
Instance Method Details
#run ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ruby_home/hap/server.rb', line 13 def run puts "Listening on #{host}:#{port}" @server = TCPServer.new(host, port) monitor = @selector.register(@server, :r) monitor.value = proc { accept } loop do @selector.select { |monitor| monitor.value.call(monitor) } end end |