class DNSSD::Reply::Resolve

Created by DNSSD::Service#resolve

Attributes

domain[R]

A domain for registration or browsing

name[R]

The service name

port[R]

The port for this service

target[R]

The hostname of the host provide the service

text_record[R]

The service's primary text record

type[R]

The service type

Public Class Methods

new(service, flags, interface, fullname, target, port, text_record) click to toggle source

Creates a new Resolve, called internally by DNSSD::Service#resolve

Calls superclass method DNSSD::Reply.new
# File lib/dnssd/reply/resolve.rb, line 39
def initialize(service, flags, interface, fullname, target, port,
               text_record)
  super service, flags, interface

  set_fullname fullname

  @target = target
  @port = port
  @text_record = DNSSD::TextRecord.new text_record
end

Public Instance Methods

connect(family = Socket::AF_UNSPEC, addrinfo_flags = 0) click to toggle source

Connects to this Reply. If target and port are missing, DNSSD.resolve is automatically called.

family can be used to select a particular address family (IPv6 vs IPv4).

addrinfo_flags are passed to DNSSD::Service#getaddrinfo as flags.

# File lib/dnssd/reply/resolve.rb, line 58
def connect(family = Socket::AF_UNSPEC, addrinfo_flags = 0)
  addrinfo_protocol = case family
                      when Socket::AF_INET   then DNSSD::Service::IPv4
                      when Socket::AF_INET6  then DNSSD::Service::IPv6
                      when Socket::AF_UNSPEC then 0
                      else raise ArgumentError, "invalid family #{family}"
                      end

  service = DNSSD::Service.new

  service.getaddrinfo target, addrinfo_protocol, addrinfo_flags,
                      @interface do |addrinfo|
    address = addrinfo.address

    begin
      socket = nil

      case protocol
      when 'tcp' then
        socket = TCPSocket.new address, port
      when 'udp' then
        socket = UDPSocket.new
        socket.connect address, port
      end

      return socket
    rescue
      next if addrinfo.flags.more_coming?
      raise
    end
  end
end