| By Kevin Hoffman | Article Rating: |
|
| July 20, 2007 10:00 PM EDT | Reads: |
10,266 |
In homage to one of the best subject lines I've seen in my spam-filtered trash box in a long time, I decided to write a post on doing some cross-platform dynamic service discovery using Zeroconf. Most of the subject lines of the spam that I get aren't related to Macs or Vista, but they're funny nonetheless. It is basically a multicast DNS protocol that provides for dynamic service publication and discovery. You've probably heard of various implementations of Zeroconf as Bonjour (formerly Rendezvous) and Avahi.
What I really like about Bonjour isn't that you can use it to discover nearby iTunes libraries for music sharing (that's how iTunes actually does use Bonjour) or that you can use Bonjour to discover nearby printers (also a legitimate use, that's how I discovered my HP scanner-fax-printer from my Mac) - it's the fact that you can use Bonjour to dynamically publish the location of services within your enterprise, including arbitrary metadata about those services. To me, this is far more compelling than the iTunes scenario. UDDI is such a huge overbloated pain in the ass, and it's not flexible or dynamic enough for me, and as a propogator of WSDL, UDDI is my enemy :)
So, I aquired a Zeroconf .NET library from this web site. This library is a wrapper for Apple's Bonjour. Basically all you need to do is first install Bonjour for Windows and this .NET library works out of the box. Take a look at how easy it is to publish the type, name, and location of a service as well as arbitrary metadata:
publishService = new NetService("", "_kevin._tcp",
"Kevin's Hot Service", 80);
System.Collections.Hashtable dict =
new System.Collections.Hashtable();
byte[] byte1 =
Encoding.UTF8.GetBytes("record1");
byte[] byte2 =
Encoding.UTF8.GetBytes("and another record.");
dict.Add("data1", byte1);
dict.Add("data2", byte2);
publishService.TXTRecordData =
NetService.DataFromTXTRecordDictionary(dict);
publishService.Publish();Now that I'm publishing the location of my hot service (I am sure there are countless hot and steamy things that can be done with said service, just like all the spams say!) I can switch over to the Mac and use some Cocoa to browse for services of type "_kevin._tcp" ... which will give me a list of all instances of my ridiculously cool service on the LAN and allow me to resolve those to addresses and ports.
Without having to aquire another library for Bonjour (support for it is built into Cocoa), I can quickly create a controller that requests a browse for services of a given type and receives notifications about hits through the (hopefully well-known if you read my blog) delegate pattern:
-(IBAction)startBrowsing:(id)sender
{
browser = [[NSNetServiceBrowser alloc] init];
[browser setDelegate:self];
[browser searchForServicesOfType:
@"_kevin._tcp" inDomain:@"local"];
}
#pragma mark browser delegate
- (void)netServiceBrowser:(NSNetServiceBrowser *)
aNetServiceBrowser
didRemoveService:(NSNetService *)aNetService
moreComing:(BOOL)moreComing
{
[servicesArray removeObject:aNetService];
}
- (void)netServiceBrowser:(NSNetServiceBrowser *)
aNetServiceBrowser
didFindService:(NSNetService *)aNetService
moreComing:(BOOL)moreComing
{
[servicesArray addObject:aNetService];
}
And without further delay, here's a screenshot of my Mac client using Bonjour to discover a service published by a .NET Framework 3.0 Windows Vista application through a .NET wrapper around Bonjour for Windows:

Pretty steamy, huh?
tags: zeroconf bonjour rendezvouz networking crossplatform
links: digg this del.icio.us technorati reddit
Published July 20, 2007 Reads 10,266
Copyright © 2007 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Kevin Hoffman
Kevin Hoffman, editor-in-chief of SYS-CON's iPhone Developer's Journal, has been programming since he was 10 and has written everything from DOS shareware to n-tier, enterprise web applications in VB, C++, Delphi, and C. Hoffman is coauthor of Professional .NET Framework (Wrox Press) and co-author with Robert Foster of Microsoft SharePoint 2007 Development Unleashed. He authors The .NET Addict's Blog at .NET Developer's Journal.
![]() |
.NET News 07/20/07 08:13:21 PM EDT | |||
What I really like about Bonjour isn't that you can use it to discover nearby iTunes libraries for music sharing (that's how iTunes actually does use Bonjour) or that you can use Bonjour to discover nearby printers (also a legitimate use, that's how I discovered my HP scanner-fax-printer from my Mac) - it's the fact that you can use Bonjour to dynamically publish the location of services within your enterprise, including arbitrary metadata about those services. To me, this is far more compelling than the iTunes scenario. UDDI is such a huge overbloated pain in the ass, and it's not flexible or dynamic enough for me, and as a propogator of WSDL, UDDI is my enemy :) |
||||
- Kindle 2 vs Nook
- Cloud Computing on Gartner's Top 10 List and SYS-CON Events' 2010 Calendar
- Confessions of a Ulitzer Addict
- IBM Hardware Chief, Intel VC Exec Arrested in Insider Trading Scam
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- Moving Your RIA Apps into the Cloud: Seven Challenges
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Windows 7 – Microsoft’s First Step to the Cloud
- Ulitzer Provides a Powerful Social Journalism Platform
- Jill Tummler Singer, Deputy CIO of CIA, Keynotes at GovIT Expo
- Open Source Mobile Cloud Sync and Push Email
- Kindle 2 vs Nook
- The Difference Between Web Hosting and Cloud Computing
- Cloud Computing on Gartner's Top 10 List and SYS-CON Events' 2010 Calendar
- Ajax in RichFaces 3.3, JSF 2 and RichFaces 4
- Confessions of a Ulitzer Addict
- IBM Hardware Chief, Intel VC Exec Arrested in Insider Trading Scam
- My Thoughts on Ulitzer
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- US Post Office Hops a Ride on NetSuite’s Cloud
- Moving Your RIA Apps into the Cloud: Seven Challenges
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Building a Drag-and-Drop Shopping Cart with AJAX
- What Is AJAX?
- Google Maps! AJAX-Style Web Development Using ASP.NET
- Flashback to January 2006: Exclusive SYS-CON.TV Interviews on "OpenAjax Alliance" Announcement
- AJAXWorld Conference & Expo to Take Place October 2-4, 2006, at the Santa Clara Convention Center, California
- AJAX Sponsor Webcasts Are Now Available at AJAXWorld Website
- How and Why AJAX, Not Java, Became the Favored Technology for Rich Internet Applications
- "Real-World AJAX" One-Day Seminar Arrives in Silicon Valley
- AJAXWorld University Announces AJAX Developer Bootcamp
- AJAX Support In JadeLiquid WebRenderer v3.1
- Where Are RIA Technologies Headed in 2008?
- Struts Validations Framework Using AJAX









































