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
- #shutdown ⇒ Object
Constructor Details
#initialize(host, port) ⇒ 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) @port = port @host = host @selector = NIO::Selector.new @status = :running 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 |
Instance Method Details
#run ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# 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 if @status == :running @selector.select { |monitor| monitor.value.call(monitor) } else @selector.close end end end |
#shutdown ⇒ Object
29 30 31 |
# File 'lib/ruby_home/hap/server.rb', line 29 def shutdown @status = :shutdown end |