Skip to Content

MDNS and caffeine: How I got Bonjour running on my iPhone

See this picture? It's a picture of my iPod touch. But here is the interesting thing. The picture you see is actually a screen shot from my iPod touch. As you can see from the iPod logo, it has no on-board camera. Instead, it's subscribed to a Bonjour service on my iPhone and using its camera instead to take a picture of itself.

Say what?

Holy. Cow. Do I ever need some rest. I just spent most of last night figuring out how to get Bonjour (aka mDNS) running on my iPhone. Bonjour offers configuration-free networking technology. Computers (and iPhones) automagically broadcast their services, which you can then listen for and take advantage of. This has been a long-term project that I've been plugging away at for months.

So what makes this exciting? With Bonjour, your iPhone and touch can talk to your Mac. They can talk to printers or to each other. They can browse for available services or provide their own as a server. What I put together was a pair of applications: PicSend and PicListen. These apps allow you to subscribe to a camera on another person's iPhone. Just tell that iPhone to snap a picture and within seconds that picture appears on your own screen.

PicSend and PicListen

You can download a copy of PicSend and PicListen from my FTP site. They work like this:

Install PicSend on any iPhone. This is the server app and needs to run on a unit with a working camera.

Install PicListen on either a touch or an iPhone. It subscribes to the PicSend service and tells the iPhone to snap pictures and send them on over.

PicSend has one button that freezes and unfreezes the camera display. When stopped, the live preview ends and a single image displays until you resume.

PicListen has one button too. It's labeled "snap". Tap it to tell the server to take a picture. If you're holding the server you know when someone snapped a picture--you'll hear the camera shutter "click".

PictureSharing and PictureSharingBrowser

Don't have two iPhones on-hand? Apple provids two sample code programs that tie right into these utilities. PictureSharingBrowser and PictureSharing both run on the Mac. Browser is the client, PictureSharing is the server. They're using the same Bonjour protocol so if you set your service to PicBrowser, you'll be able to send pictures to your iPhone or see pictures from the iPhone on your Mac.

To send a picture to, say, your iPod touch, just drop it into PictureSharing and press Start. PicListen will scan for Bonjour services, find the picture, and display it.

Similarly, PictureSharingBrowser allows you to see the pictures you snap on your iPhone.

Programming

Normally programming in Bonjour is really easy. That's because Apple offers some fabulous Objective-C classes (like NSNetServices) that take care of most of the messy bits. In the world of Apple, everything that is Cocoa and Objective-C is good and lovely and yummy. Unfortunately, although the Bonjour daemon comes pre-installed on iPhone, the supporting classes did not.

That leaves us in the world of Core Foundation. Everything that is CF is bad, and evil, and C++-like, and just...messy. Everything you can do in heavenly Objective-C, you can do in evil Core Foundation. I spent hours laboriously porting Apple's CFNetServices samples to iPhone.

So what's the big deal?

Sending pictures back and forth between iPhones isn't a huge deal until you realize that you're not limited to pictures. With Bonjour, you can send files, data, sounds, videos, anything that transfers from one computer to another. I'm hoping to adapt the code to work next with sound. Sure, you can do a lot better at Target in terms of buying sub-$400 walkie-talkies, but again we're dealing with baby steps here. I'm hoping that the iPhone will soon be able to "discover" printers in its area and offer to print out pictures or webpages or people can use Bonjour to play interactive games. The possibilities of social computing with iPhones, iPod touches and Bonjour are practically limitless.

Got some ideas, suggestions or requests? Let me know in the comments.

Thanks to GeeKdLL and Drudge for testing.



Categories

Cool tools Hacks iPhone

See this picture? It's a picture of my iPod touch. But here is the interesting thing. The picture you see is actually a screen shot from...
 

Add a Comment

*0 / 3000 Character Maximum

66 Comments

Filter by:
eric

10base-t interactive (makers of dropcopy) just released a free,  open-source iPhone/Touch compatible cocoa class that wraps CFNetwork code to provide native bonjour publishing and browsing support on the iPhone/Touch.

To add bonjour to their native apps, developers need only include 10base-t interactive's new CFBonjour class to gain access to straightforward new cocoa methods such as:

CFBonjourStartBrowsingForServices: serviceType: inDomain:

and

CFBonjourPublishWithService: machineID: onPort:

full source, API documentation and an example project are available at: http://10base-t.com/source/cfbonjour.zip 

November 07 2007 at 1:41 PM Report abuse rate up rate down Reply
eric

well erica, again you continue to push the limits on what my little iphone can do! kudos for all the hard work! i really have no suggestions for you, other than camcording possibilites:)) but im sure in about 3 days ill get a pop up in my installer app of some crazy new app! cant wait to see what it is! hopefully that camcorder!!!
thanks!

October 30 2007 at 6:09 PM Report abuse rate up rate down Reply
tk.

Erica rocks :)

October 24 2007 at 12:12 PM Report abuse rate up rate down Reply
Louis Tristan

Wow! That's amazing! I was just talking about that the other day...Can't wait to go home n try it...Thanks! Yeah when do you sleep?

October 24 2007 at 11:02 AM Report abuse rate up rate down Reply
Andre

Are there any checks in place to ensure that only 'authorised' users can use the phone camera remotely? Maybe something like the Bluetooth method of generated pass-key and and confirmation on the other device?

October 24 2007 at 9:38 AM Report abuse rate up rate down Reply
mo

what about a mac remote control? or a starbuck like in this room people listen to this music! ;)

that would be really fun!!!

October 24 2007 at 9:04 AM Report abuse rate up rate down Reply
qryptiq

thanks erica,

maybe this is related - maybe not. is it possible to display video here and there? such as a video playing on my computer and simultaneously playing it on the iphone....

oh, any instructions on how to install bonjour on the iphone?

October 24 2007 at 7:33 AM Report abuse rate up rate down Reply
Peter Payne

A pretty flower for the pretty hacker.

October 23 2007 at 10:59 PM Report abuse rate up rate down Reply
Anthony

how about instructions? im no noob but it seems to me that piclisten doesnt work when i open it just stays blank. im just trying to see if it asks what to connect to or anything like that. picsend works fine just dont know how to get piclisten to work.

October 23 2007 at 9:27 PM Report abuse rate up rate down Reply
Scott

wow erica... You're great. Sound would be nice. Especially if you could do sound or picture over the net with a computer or iPhone/touch

October 23 2007 at 8:35 PM Report abuse rate up rate down Reply
Buy an ad here

Hot Apps on TUAW

Tweets

© 2012 AOL Inc. All Rights Reserved.