Multicast on Android 2.2
Asked Answered
C

3

17

Has anyone gotten Multicast to work on Android 2.2, specifically JmDNS for Bonjour service detection. There are many questions & answers from the Android 1.5->2.0 timeframe, including on stackOverflow, that indicate varying levels of success, and a bug in the bug tracker that indicate it was fixed, and closed, for 2.2 (http://code.google.com/p/android/issues/detail?id=2323) . I've tried the "TuneControl" source code, but that worked on ~1.5 and has not been updated, and does not work for me on 2.2.

So, the questions... 1) Has anyone seen multicast work on 2.2, specifically JmDNS, and specifically for Bonjour service detection?

2) What is necessary in code to make this work?

I'm using the appropriate permissions:

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

<uses-permission android:name="android.permission.INTERNET"/>

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>

I acquire the multicast lock:

WifiManager wifi = (WifiManager)getSystemService( Context.WIFI_SERVICE );
if(wifi != null)
{
    MulticastLock mcLock = wifi.createMulticastLock("mylock");
    mcLock.acquire();
...

And then try to start jmDNS to look for servers:

    mdns = JmDNS.create(addr, HOSTNAME);
    jmdns.addServiceListener(TOUCH_ABLE_TYPE, listener);
    jmdns.addServiceListener(DACP_TYPE, listener);
    ...

The listener never sees any services. I've verified using Wireshark that the request packets are sent, and that the server responds, but the response packet are never seen by the socket listener code in the jmDNS library.

So... am I missing something? Is this still a bug? Has ANYONE gotten anything even remotely like this to work???

Circumflex answered 2/9, 2010 at 0:59 Comment(0)
C
13

To (rudely) answer my own question, more information was provided at http://code.google.com/p/android/issues/detail?id=2917#c48 by another person. For posterity, as they say, here is [email protected]'s answer...

"I've spent quite a bit of time debugging mDNS issues with JmDNS on my Evo and HTC Hero (CDMA). What I found is there appears to be a filter in place in the broadcom wireless driver on the Evo (and since I'm getting a similiar reprt from an HTC Desire user - with the same chipset, presumably that handset as well). The filter, by default, blocks any non-unicast or network broadcast traffic, including multicast. Apparently the theory was it's a battery saver.

The problem appears to be the wpa_supplicant on the Evo does not support removing those filters when you get a MulticastLock. (Check the log output right after you get the lock and you'll see what I mean). Unfortunately what has happened is the hardware vendors have fragmented multicast support.... :("

So... it appears this is a device problem more than a coding problem. D'oh. :( If I get an opportunity to test on another device...

Circumflex answered 15/9, 2010 at 5:16 Comment(2)
multicast handling on Android really is problematic at this point (2.2).Averil
I get the "multicast lock" OK on my Samsung Galaxy S device but I only receive the packets I sent out. To go around this problem for my application, I am building a Web Service that will be used to "register" the LAN services I want to control with my Android devices. This way, I am not dependent on multicast availability on the hardware.Averil
S
8

I've been doing a bit of research into this, and I believe it is a problem with Android in general, and fixed in or around Android 2.3.7.

It's a bit too anecdotal, but here's what I tested:

  • HTC Desire, 2.2, stock: fail
  • HTC Desire, 2.3.7, CyanogenMod: success
  • Motorola Milestone, 2.1-update1: fail
  • HTC Desire S, 2.3.3: fail
  • Acer Iconia A501, 3.2.1: success
  • Samsung something, 2.3.3: fail
  • HTC Legend, 2.2 I think: fail

When I say 'fail', in fact they were all able to send multicast messages to the 'success' devices, but never receive anything back except their own messages - as jldupont describes.

Note that the multicast IM app Kouchat is only available for 2.3.7 onwards, even though it can be made to compile for as far back as 2.1, which gives further credence to this theory.

Shoon answered 23/3, 2012 at 9:8 Comment(3)
Thanks Rob for the info, I am new to multicast. Do you think I would be able to send multicast packet from android HTC desire API-8 to Windows PC ?Sunstone
API level 8 is 2.2, so I think that you will be able to send from the Desire to the PC, but the Desire will not be able to receive anything back.Shoon
Thanks, I will try it out, for me just sending would be enough because me android is a server and clients need to discover it..Sunstone
V
1

I think the other reason is your AP does not support.

Other:Computer send/recieve to/from Android

your computer must only use WIFI,Best off all other network

Vulpecula answered 13/7, 2012 at 2:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.