Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multicast Support on Android in Hotspot/Tethering mode

I have a prototype Android app that is listening for multicast packets to 'discover' clients to communicate with. The socket set up is similar to this:

InetAddress group = InetAddress.getByName("228.1.2.3");
MulticastSocket s = new MulticastSocket(4000);
s.joinGroup(group);

This works very well when all the devices are connected via WiFi. I would like to support this with the phone acting as a portable hotspot. However, while all my devices appear to connect to the hotspot correctly I no longer receive multicast data. I'm wondering if there are restrictions that disallow this type of communication in hotspot mode, or if there are is any additional network configuration required to enable this? I've tried this on a couple different devices running Gingerbread and Froyo with no luck.

like image 894
Sarge Avatar asked Jul 01 '11 16:07

Sarge


People also ask

Can you use your phone as a hotspot while connected to Wi-Fi?

To turn your Android phone into a hotspot, go to Settings, then Mobile Hotspot & Tethering. Tap on Mobile Hotspot to turn it on, set the name of your network and set a password. You connect a computer or tablet to your phone's Wi-Fi hotspot just as you would connect to any other Wi-Fi network.


1 Answers

As this article show: https://plus.google.com/+Chainfire/posts/9NMemrKYnCd

MulticastSocket::setNetworkInterface()

would be the answer

you can find the wlan0 eth by :

public static NetworkInterface getWlanEth() {
    Enumeration<NetworkInterface> enumeration = null;
    try {
        enumeration = NetworkInterface.getNetworkInterfaces();
    } catch (SocketException e) {
        e.printStackTrace();
    }
    NetworkInterface wlan0 = null;
    StringBuilder sb = new StringBuilder();
    while (enumeration.hasMoreElements()) {
        wlan0 = enumeration.nextElement();
        sb.append(wlan0.getName() + " ");
        if (wlan0.getName().equals("wlan0")) {
            //there is probably a better way to find ethernet interface
            Log.i(TAG, "wlan0 found");
            return wlan0;
        }
    }

    return null;
}

Have a try and lemme know if it works or not in Hotspot mode...

like image 100
user707606 Avatar answered Oct 07 '22 09:10

user707606