Class: RubyHome::HAP::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_home/hap/server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#hostObject (readonly)

Returns the value of attribute host.



10
11
12
# File 'lib/ruby_home/hap/server.rb', line 10

def host
  @host
end

#portObject (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

#runObject



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