Class: Tojour::Jour

Inherits:
Object
  • Object
show all
Defined in:
lib/tojour/jour.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, kind) ⇒ Jour

Returns a new instance of Jour.



5
6
7
8
# File 'lib/tojour/jour.rb', line 5

def initialize(name, kind)
  @name = name
  @protocol = "_tojour_#{kind}._tcp"
end

Class Method Details

.list(&block) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/tojour/jour.rb', line 28

def self.list(&block)
  %w[file io].each do |kind|
    DNSSD.browse("_tojour_#{kind}._tcp") do |r|
      block.call(kind, r.name)
    end
  end
  sleep 5
end

Instance Method Details

#register(port, &block) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/tojour/jour.rb', line 10

def register(port, &block)
  DNSSD::register(@name, @protocol, nil, port) do |r|
    block.call(r)
  end
  loop do
    sleep 1
  end
end

#resolve(&block) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/tojour/jour.rb', line 19

def resolve(&block)
  DNSSD.resolve(@name, @protocol, 'local') do |r|
    block.call(r)
  end
  loop do
    sleep 1
  end
end