-
-
Save dbgrandi/229878 to your computer and use it in GitHub Desktop.
Using the NSNetServiceBrowser with macruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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