A simple example of using Bonjour with MacRuby
Switch branches/tags
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



Salut is just a little bit of example code of using Bonjour with MacRuby.

If all you want to do is log that callbacks were called back, or just add very little to a callback, then this code will work well for you. But Apple has already done a very good job of distilling Bonjour to the point that even without this gem you would not have to add much code in order to use Bonjour.

Of course, this is not a substitute for reading the Bonjour Overview and related documentation (not even close).

Reference Documentation

Apple's superb documentation of Bonjour and the Bonjour Objective-C interface:

Example Usage

Advertising a hypothetical service:

        service = Salut::Service.new(

Finding the service using the browser:

        browser = Salut::Browser.new
        # the NSNetServiceBrowserDelegate lists all the possible delegates
        # or look at the 'Delegate methods' group in lib/Salut/Browser.rb
        browser.delegate :"netServiceBrowser:didFindService:moreComing:" do
            |sender, service, more|
            service.resolve # if you want to resolve all services found
            if more
               NSLog('Not up to date yet')
               NSLog('All caught up')
        browser.find_services '_http._tcp.'

If you want to stop advertising:


You might notice that you aren't seeing the results of the callbacks, this is because they are waiting for the current run loop to cycle. This would happen automatically with a GUI app, but a command line app will have to force the loop to run.

       NSRunLoop.currentRunLoop.run  # => runs indefinitely
       NSRunLoop.currentRunLoop.runUntiDate (Time.now + 5)  # => runs for 5 seconds

You can only use a Service or Browser for one thing at a time, and the API is designed with that assumption in mind.

TODO for 1.0

  • Monitoring and TXT record stuff
  • publishWithOptions default argument
  • implement a mapping for Hot Cocoa

Contributing to Salut

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
  • Fork the project
  • Start a feature/bugfix branch
  • Commit and push until you are happy with your contribution
  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.


Copyright (c) 2010-2011 Mark Rada. See LICENSE.txt for further details.