views:

1457

answers:

3

I'm working with a Droid / Android 2.0.1 and encountering an issue apparently many people have: I'm unable to discover services using the one pure-Java zeroconf library I know of, jmDNS. (Apple's Bonjour, while it works on Linux and Windows Java, I believe would be harder to port to Android because of reliance on native code.)

I can create services, but not discover them. I'm trying to make sense of what's going on.

There is an ongoing issue report here; related to multicast and IPv6, but seems to be throwing users of jmDNS, too: http://code.google.com/p/android/issues/detail?id=2323

Any idea why this person might be having success? See comment 22 in the bug report. (I'm new to SO, so can't post more than one URL.)

I have tested their code, but without any luck.

Has anyone successfully accomplished zeroconf service discovery on Android, using jmDNS or another library?

Is it possible my discovery issue is related to the IPv6 multicast problem?

+2  A: 

Have you explicitly acquired the multicast lock so that you can receive the multicast packets?

AndroidManifest.xml:
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />

// Networking code:
WifiManager wifi = (WifiManager)getSystemService(Context.WIFI_SERVICE);
MulticastLock lock = wifi.createMulticastLock("mylock");
lock.acquire();

According to that Android Issue thread it looks like 2.0.1 doesn't have the fix. Perhaps you should transition to a later release?

smountcastle
+3  A: 

I'm new as well otherwise I would have just left a comment on smountcastle's answer which is mostly correct. I have just been dealing with the exact same issue on a Droid running Android 2.1. I found that I needed to set the MulticastLock to reference-counted otherwise it seemed to be released automatically.

AndroidManifest.xml:
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />

// Networking code:
WifiManager wifi = getSystemService( Context.WIFI_SERVICE );
MulticastLock lock = wifi.createMulticastLock("fliing_lock");
lock.setReferenceCounted(true);
lock.acquire();

Just make sure to call lock.release() when you're done with it. This may only be necessary for Android 2.0+, The Droid is my only test device currently, so I can't say for sure.

Churlbong
So close to being able to make general comments... I am using JmDNS, I have had success with it on a Motorola Droid running 2.1-update1 using the MulticastLock approach. Just recently got an HTC Incredible running the same version of Android, and service discovery doesn't work using the exact same code. I've been pulling my hair out on that one, good luck...
Churlbong
A: 

Thanks, Churlbong - out of curiosity, are you using jmDNS or just writing the client implementation outright? (or using another library)?

I'll give this a try, as my lock code isn't quite the same and I'm not sure I was aware it also had a separate permission independent of the network permission. ;)

Peter Kirn
-1: This is not an answer, please delete and repost this as a comment
Casebash