1

I know that the newest Android releases allow to automatically fall back data connection over 4G when the wifi network does not provide internet connectivity.

I would like to exploit this behavior in the following scenario:

  1. An Android 8 smartphone is connected to a WiFi connection that is not wired to the internet

  2. The smartphone is connected to the internet using a 4G data connection

I want my app to send and receive Multicast packets over the WiFi network. I tried the following:

    MulticastSocket clientSocket = new MulticastSocket(1900);
    clientSocket.setInterface(getFirstWiFiAddress()); // here I set the InetAddress of the Wifi card
    clientSocket.joinGroup(InetAddress.getByName("239.255.255.250"));
    clientSocket.send(sendPacket);
    byte[] receiveData = new byte[1024];
    DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
    clientSocket.receive(receivePacket); // <--- Timeout Error (Only happens if 4G is enabled)

I can't understand why this error only happens when 4G is enabled. How can I overcome this problem?

Basically I need to trigger a wifi camera (it has its own wifi network where it broadcasts SSDP packets) while being connected to the internet.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
xanz
  • 221
  • 3
  • 10
  • 1
    Are you sure you can? Lots of ISPs filter out multicast. I would not be surprised if your wireless carrier did so. In fact I'd be more surprised if they didn't. – Gabe Sechan Dec 06 '18 at 18:14
  • I need to multicast only over wifi. Why does having a 4G connection active prevent me to multicast over the WiFi interface? What am I doing wrong? If I disable 4g data connectivity everything works fine. – xanz Dec 06 '18 at 18:20
  • You might increase [socket timeout](https://stackoverflow.com/a/40055466/3290339) or catch the exception and retry, if applicable. – Onik Dec 06 '18 at 21:03

0 Answers0