|
So I was sitting down in the labs the other day with a few minutes of spare time. I was thinking back to a PDC or some other conference I attended where they were showing off some fantastic new technology in the .NET Framework by creating an Attendee chat program. It basically worked similarly to MSN messenger. You turned the app on and you were suddenly in touch with all the attendees of PDC.
Anyway, I decided to see what something like this might look like in Cocoa. I decided to use Bonjour and Distributed Objects. Using Bonjour was a no-brainer... its fantastic and allows me to broadcast the presence of any service I am hosting to my subnet and optionally beyond.
The app I built basically works like this. You start up the application and it tells the local subnet that a service of type "_wwdc_chat._tcp." is up and running with whatever name the user chose. For example, I started mine up, called myself "Kevin", and the app was then advertising the existence of a service named "Kevin" of type "_wwdc_chat._tcp." on my machine.
The app then sets up a browser for all services of that type. Every time a service is added or removed of that type, my app will be automatically notified. This means that when people come online and go offline, the app gets notified. Pretty slick! To send someone a message, all I have to do is pick them from the dropdown list, resolve the address of the service asynchronously, and when I get the address of the service being hosted by that particular user, I can then use Cocoa's Distributed Objects to send a chat message to that user.
Anyone want to venture a guess as to how long it took this Cocoa newbie to write this app? Including spending 30 minutes figuring out some weird memory management issue that arose from my lack of understanding of the NSNetServiceBrowser class, it took me 1 hour and 31 minutes (I clocked it..).
And to show you that this isn't just some silly toy application, here's a screenshot of me monitoring the multicast DNS entries coming in and out for a given service type:
I was hoping you would seed the Developer Preview you got. :(
Hah, I've been running the developer preview of Leopard since 12:30pm on
the day of the keynote. I'm loving it.
If you have seen a 6'6", red-headed giant wandering around wwdc, that is
me. say hello if you get behind me on the escalator. :)
That's you? I think you stepped on me the other day... :)
Kevin - any chance you might share the code for that app for us who are
starting to ramp up on Cocoa development? :-)
Keep your eyes peeled to this blog. I will eventually be posting more and
more Cocoa code, including a more robust example of the P2P chat app.