Ricardo's Blog

  • 06:13:07 pm on April 18, 2010 | 8
    Tags: ,

    Multicast DNS (MDNS) is a little-known feature of DNS that allows you to automatically discover services and appliances attached to your network. Chances are you’re already using it with various household protocols such as Universal Plug and Play (UPNP) and Zeroconf/Bonjour.

    Basically, services and appliances can discover each other just by plugging them into the local network: nice and simple!

    Obviously, this makes a natural fit for smart phone applications, where simplicity is a virtue so it would be nice if my Android apps could use MDNS. Fortunately, a sophisticated MDNS Java API already exists: JmDNS. JmDNS is a nice fit for Android because it has no external dependencies and it’s already threaded.

    Unfortunately, JmDNS is also poorly documented. Recently, I’ve been trying to get JmDNS to play nice in Android, so I thought I’d make a note of a couple of the gotchas I’ve come across:

    1. Catch Service Resolved Events: There are three stages for service discovery within JmDNS: services are added, resolved and then removed. Events exist for each of these. A service added event indicates that a service has been found only: if you want to connect to the service you don’t want to catch this event. Instead, you want the service resolved event. This indicates that all relevant service information, including the IP address and port number have been found.
    2. Make sure your services are running on IPv4: Multicast DNS resolves the service’s host IP address by decoding it from the DNS messages sent from an MDNS server. If your service is running IPv6 this might cause problems: the Android emulator does not support IPv6, so if it decodes an IPv6 address you’ll get a “bad socket” exception when you attempt to open a connection. You might need to disable IPv6 on your server operating system.

    That said, there is some evidence that Android doesn’t actually support Multicast DNS on handsets, so we’ll see how far we get but, hopefully, if you’re having problems this will at least get you started.



  • Chris Gragsone 7:31 pm on August 29, 2010 | # | Reply

    “That said, there is some evidence that Android doesn’t actually support Multicast DNS on handsets, so we’ll see how far we get but, hopefully, if you’re having problems this will at least get you started.”

    The answer seems to be Maybe. Christian Koestlin has an app simply called “Network Browser” that does mDNS lookup.


    I have it on my hand held, HTC MyTouch. However looking through the comments it seems to have issues on HTC Desire and HTC Orange.

    So Android supports it, but its possible that different handhelds do not. I know I’m looking forward to writing some code for my handheld 🙂

  • chorlo 4:03 pm on November 17, 2010 | # | Reply

    UPnP does not use mDNS.

  • Mudit 11:28 am on January 11, 2011 | # | Reply


    i am trying to use Zeroconf [jmDNS lib] in my app. Can you help me with some code snippet of how are you discovering the devices in the network?

  • keith 5:55 am on April 6, 2011 | # | Reply

    JmDNS is designed to support multicast DNS inquiries on Android. The only issues apparently are in the way each device is designed; most of the HTC phones I’ve encountered on the web (as I’ve only tried HTC Desire) have WiFi driver problems that cause mDNS queries to not arrive.

  • Kozlov 1:25 am on July 27, 2011 | # | Reply

    am trying to work with UPNP over USB .But multicast not working.When i send multicast advertising packet am getting “network not reachable” java exception.

    Any clue?


  • Anand 1:43 pm on November 11, 2011 | # | Reply

    After lot of research on Multicast, I end up with a small summary and also got it to work.

  • Carlos Vega (@cavega_) 1:49 am on November 21, 2012 | # | Reply

    Ricardo, I never got a working code working because of other projects, but I wanted to as least share some links I found that might complement the info you provided:

    tutorial: http://home.heeere.com/tech-androidjmdns.html

    fix for Android4.0+: http://snctln.com/2012/08/03/jmdns-and-android-4-0/

    Melloware’s tunesremote-plus app source code (they also developed Zeroconf and use jmDNS): http://code.google.com/p/tunesremote-plus/source/browse/trunk/src/org/tunesremote/LibraryActivity.java

    Based on the brief research I did after reading your link and the above ones, it seems that only Android 2.2 and above work properly with the jmDNS library. For example, the ZeroConf Browser app only support 2.0+

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: