Skip to content

Instantly share code, notes, and snippets.

@dbgrandi
Forked from voodootikigod/netservices_macruby.rb
Created November 9, 2009 11:15
Show Gist options
  • Save dbgrandi/229878 to your computer and use it in GitHub Desktop.
Save dbgrandi/229878 to your computer and use it in GitHub Desktop.
Using the NSNetServiceBrowser with macruby
delegate = Object.new
def delegate.netServiceBrowserWillSearch(browser)
puts "search commencing!"
end
def delegate.netServiceBrowser(browser, didFindService:service, moreComing:more)
# this never calls regardless of the services on the network.
puts "Found service #{service.name}."
end
def delegate.netServiceBrowser(browser, didFindDomain:domain, moreComing:more)
puts "Found domain #{domain.inspect}."
end
def delegate.netServiceBrowser(browser, didRemoveService:service, moreComing:more)
puts "lost service #{service.name}"
end
def delegate.netServiceBrowser(browser, didNotSearch:errorInfo)
puts "search not successful: #{errorInfo}"
end
browsers = []
["growl","ssh", "raop", "http", "git", "daap", "ipp"].each{|svc|
browser = NSNetServiceBrowser.new
browser.delegate = delegate
browser.searchForServicesOfType("_#{svc}._tcp.", inDomain:"")
browsers << browser
puts "searching for #{svc}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment