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:
An Android 8 smartphone is connected to a WiFi connection that is not wired to the internet
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.