Class: Settlers::Bonjour

Inherits:
Object
  • Object
show all
Includes:
Observable, Observer
Defined in:
lib/settlers/bonjour.rb

Constant Summary collapse

TYPE =
'_settlers._tcp'

Instance Method Summary collapse

Methods included from Observer

#update

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