Class: Columbus::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/columbus/client.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.discover_typeObject

Returns the value of attribute discover_type.



24
25
26
# File 'lib/columbus/client.rb', line 24

def discover_type
  @discover_type
end

Class Method Details

.discover(timeout = 5) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/columbus/client.rb', line 30

def discover(timeout=5)
  waiting_thread = Thread.current

  dns = DNSSD.browse discover_type do |reply|
    DNSSD.resolve reply.name, reply.type, reply.domain do |resolve_reply|
      service = FoundService.new(reply.name,
                                resolve_reply.target,
                                resolve_reply.port,
                                (resolve_reply.text_record['description'].to_s rescue ""))
      begin
        yield service
      rescue Done
        waiting_thread.run
      end
    end
  end
  
  sleep timeout
  dns.stop
end

.listObject



57
58
59
60
61
62
63
# File 'lib/columbus/client.rb', line 57

def list
  service_list.each do |service|
    puts "=== #{service.name} on #{service.host}:#{service.port} ==="
    puts " found #{service.name}"
    puts "    #{service.description}"
  end
end

.service_listObject



51
52
53
54
55
# File 'lib/columbus/client.rb', line 51

def service_list
  list = Set.new
  discover { |obj| list << obj }
  return list
end