0

I found some examples for setting up a multicast socket server (receiving) in Android and I'm trying to add that to my project. My constructor code looks like this:

try
{
    this.socket = new MulticastSocket (PORT);
    socket.joinGroup (InetAddress.getByName (MULTICAST_ADDRESS));
}
catch (Exception ex)
{
    Log.e (TAG, "Start up error: " + ex.getMessage());
    ex.printStackTrace();

    this.running = false;
}

However, for reasons I don't understand, every time the joinGroup() line is executed an exception is thrown. Strangely, the printStackTrace() line doesn't give me anything, but the Log.e() business gives me the following:

Multicast Server: Start up error: setsockopt failed: ENODEV (No such device)  

I have added the necessary permissions to my code (CHANGE_WIFI_MULTICAST_STATE, ACCESS_WIFI_STATE, & INTERNET), and I have acquired a Multicast lock as well.

Any suggestions at what's missing here?

user207421
  • 305,947
  • 44
  • 307
  • 483
Rich
  • 4,157
  • 5
  • 33
  • 45
  • Possible duplicate of [Multicast - no such device](http://stackoverflow.com/questions/8180275/multicast-no-such-device) – user207421 Mar 30 '16 at 22:17

1 Answers1

0

By a round-about-path, this question became the same as mine:

http://stackoverflow.com/questions/8180275/multicast-no-such-device

And the answer turns out to be that I needed to specify the interface, since my fancy Panasonic Android tablet has more than one:

try
{
    NetworkInterface eth0 = null;
    Enumeration<NetworkInterface> enumeration = NetworkInterface.getNetworkInterfaces();

    while (enumeration.hasMoreElements())
    {
        eth0 = enumeration.nextElement();

        if ("eth0".equalsIgnoreCase (eth0.getName()))
        {
            break;
        }
    }

    this.socket = new MulticastSocket (PORT);
    socket.setSoTimeout (60000);
    socket.joinGroup (new InetSocketAddress (MULTICAST_ADDRESS, PORT), eth0);
}
catch (Exception ex)
{
    ...
Rich
  • 4,157
  • 5
  • 33
  • 45