Module: DNSSD

Defined in:
ext/rdnssd_service.c,
ext/rdnssd_structs.c,
ext/rdnssd_tr.c

Defined Under Namespace

Classes: Flags, Reply, Service, TextRecord

Class Method Summary collapse

Class Method Details

.browse(type, domain = nil, flags = 0, interface = DNSSD::InterfaceAny) {|reply| ... } ⇒ Object

Asynchronously browse for services. For each service found a DNSSD::BrowseReply object is passed to block. The returned service_handle can be used to control when to stop browsing for services (see DNSSD::Service#stop).

s = DNSSD.browse('_http._tcp') do |b|
  puts "found: #{b.inspect}"
end

Yields:

  • (reply)


449
450
451
452
453
454
455
# File 'ext/rdnssd_service.c', line 449

static VALUE
dnssd_browse(int argc, VALUE * argv, VALUE self)
{
	return dnssd_service_start_in_thread(
		sd_browse(argc, argv, dnssd_service_alloc(rb_block_proc()))
																			);
}

.browse!(type, domain = nil, flags = 0, interface = DNSSD::InterfaceAny) {|reply| ... } ⇒ Object

Synchronously browse for services. For each service found a DNSSD::Reply object is passed to block.

timeout(6) do
  DNSSD.browse!('_http._tcp') do |r|
    puts "found: #{r.inspect}"
  end
rescue TimeoutError
end

Yields:

  • (reply)

Returns:

  • (Object)


426
427
428
429
430
431
432
# File 'ext/rdnssd_service.c', line 426

static VALUE
dnssd_browse_bang(int argc, VALUE * argv, VALUE self)
{
	return dnssd_service_start(
		sd_browse(argc, argv, dnssd_service_alloc(rb_block_proc()))
														);
}

.enumerate_domains(flags = 0, interface = DNSSD::InterfaceAny) {|reply| ... } ⇒ Object

Asynchronously enumerate domains available for browsing and registration. For each domain found a DNSSD::DomainEnumReply object is passed to block. The returned service_handle can be used to control when to stop enumerating domains (see DNSSD::Service#stop).

available_domains = []
s = DNSSD.enumerate_domains do |d|
  available_domains << d.domain
end
sleep(0.2)
s.stop
puts available_domains.inspect

Yields:

  • (reply)


355
356
357
358
359
360
361
# File 'ext/rdnssd_service.c', line 355

static VALUE
dnssd_enumerate_domains(int argc, VALUE * argv, VALUE self)
{
	return dnssd_service_start_in_thread(
		sd_enumerate_domains(argc, argv, dnssd_service_alloc(rb_block_proc()))
																			);
}

.enumerate_domains!(flags = 0, interface = DNSSD::InterfaceAny) {|reply| ... } ⇒ Object

Synchronously enumerate domains available for browsing and registration. For each domain found a DNSSD::Reply object is passed to block with #domain set to the enumerated domain.

  available_domains = []
  timeout(2) do
	  DNSSD.enumerate_domains! do |r|
	    available_domains << r.domain
    end
  rescue TimeoutError
  end
  puts available_domains.inspect

Yields:

  • (reply)

Returns:

  • (Object)


329
330
331
332
333
334
335
# File 'ext/rdnssd_service.c', line 329

static VALUE
dnssd_enumerate_domains_bang (int argc, VALUE * argv, VALUE self)
{
	return dnssd_service_start(
		sd_enumerate_domains(argc, argv, dnssd_service_alloc(rb_block_proc()))
														);
}

.register(name, type, domain, port, text_record = nil, flags = 0, interface = DNSSD::InterfaceAny) {|reply| ... } ⇒ Object

Asynchronously register a service. A DNSSD::Reply object is passed to the block when the registration completes. The returned service_handle can be used to control when to stop the service (see DNSSD::Service#stop).

# Start a webserver and register it using DNS Service Discovery
require 'dnssd'
require 'webrick'

web_s = WEBrick::HTTPServer.new(:Port=>8080, :DocumentRoot=>Dir::pwd)
dns_s = DNSSD.register("My Files", "_http._tcp", nil, 8080) do |r|
  warn("successfully registered: #{r.inspect}")
end

trap("INT"){ dns_s.stop; web_s.shutdown }
web_s.start

Yields:

  • (reply)


567
568
569
570
571
572
573
# File 'ext/rdnssd_service.c', line 567

static VALUE
dnssd_register(int argc, VALUE * argv, VALUE self)
{
	return dnssd_service_start_in_thread(
		sd_register(argc, argv, dnssd_service_alloc(rb_block_proc()))
																			);
}

.register!(name, type, domain, port, text_record = nil, flags = 0, interface = DNSSD::InterfaceAny) {|reply| ... } ⇒ Object

Synchronously register a service. A DNSSD::Reply object is passed to the block when the registration completes.

DNSSD.register!("My Files", "_http._tcp", nil, 8080) do |r|
  warn("successfully registered: #{r.inspect}")
end

Yields:

  • (reply)

Returns:

  • (Object)


537
538
539
540
541
542
543
# File 'ext/rdnssd_service.c', line 537

static VALUE
dnssd_register_bang(int argc, VALUE * argv, VALUE self)
{
	return dnssd_service_start(
		sd_register(argc, argv, dnssd_service_alloc(rb_block_proc()))
														);
}

.resolve(name, type, domain, flags = 0, interface = DNSSD::InterfaceAny) {|reply| ... } ⇒ Object

Asynchronously resolve a service discovered via DNSSD.browse(). The service is resolved to a target host name, port number, and text record - all contained in the DNSSD::Reply object passed to the required block. The returned service_handle can be used to control when to stop resolving the service (see DNSSD::Service#stop).

s = DNSSD.resolve("foo bar", "_http._tcp", "local") do |r|
  puts r.inspect
end
sleep(2)
s.stop

Yields:

  • (reply)


667
668
669
670
671
672
673
# File 'ext/rdnssd_service.c', line 667

static VALUE
dnssd_resolve(int argc, VALUE * argv, VALUE self)
{
	return dnssd_service_start_in_thread(
		sd_resolve(argc, argv, dnssd_service_alloc(rb_block_proc()))
																			);
}

.resolve!(name, type, domain, flags = 0, interface = DNSSD::InterfaceAny) {|reply| ... } ⇒ Object

Synchronously resolve a service discovered via DNSSD.browse(). The service is resolved to a target host name, port number, and text record - all contained in the DNSSD::Reply object passed to the required block.

timeout(2) do
  DNSSD.resolve!("foo bar", "_http._tcp", "local") do |r|
    puts r.inspect
  end
rescue TimeoutError
end

Yields:

  • (reply)

Returns:

  • (Object)


641
642
643
644
645
646
647
# File 'ext/rdnssd_service.c', line 641

static VALUE
dnssd_resolve_bang(int argc, VALUE * argv, VALUE self)
{
	return dnssd_service_start(
		sd_resolve(argc, argv, dnssd_service_alloc(rb_block_proc()))
														);
}