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.
Instance Method Summary collapse
-
#initialize(host, port) ⇒ Server
constructor
A new instance of Server.
- #run ⇒ Object
Constructor Details
#initialize(host, port) ⇒ Server
Returns a new instance of Server.
4 5 6 7 8 |
# File 'lib/ruby_home/hap/server.rb', line 4 def initialize(host, port) @port = port @host = host @selector = NIO::Selector.new end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
10 11 12 |
# File 'lib/ruby_home/hap/server.rb', line 10 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
10 11 12 |
# File 'lib/ruby_home/hap/server.rb', line 10 def port @port end |
Instance Method Details
#run ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/ruby_home/hap/server.rb', line 12 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 |