Class: Settlers::Bonjour
- Inherits:
-
Object
- Object
- Settlers::Bonjour
- Includes:
- Observable, Observer
- Defined in:
- lib/settlers/bonjour.rb
Constant Summary collapse
- TYPE =
'_settlers._tcp'
Instance Method Summary collapse
-
#server_exists_at(address) ⇒ Object
To confirm registration is working, run ‘mDNS -B _settlers._tcp`.
- #start(timeout = 5) ⇒ Object
Methods included from Observer
Instance Method Details
#server_exists_at(address) ⇒ Object
To confirm registration is working, run ‘mDNS -B _settlers._tcp`.
12 13 14 |
# File 'lib/settlers/bonjour.rb', line 12 def server_exists_at(address) DNSSD.register!(address.name, TYPE, nil, address.port) end |
#start(timeout = 5) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/settlers/bonjour.rb', line 16 def start(timeout=5) puts "Looking for servers for up to #{timeout} seconds..." DNSSD.browse(TYPE) do |browse| DNSSD.resolve(browse) do |reply| DNSSD.getaddrinfo!(reply.target, DNSSD::Service::IPv4) do |info| changed notify_observers :server_exists_at, Address.from(reply, info) end end end sleep timeout end |