My service receives udp messages. This code always works:
InetSocketAddress inetSocketAddress = new InetSocketAddress(InetAddress.getByName(myIpAddress), udpPort);
DatagramSocket socket = new DatagramSocket(null);
socket.setReuseAddress(true);
socket.bind(inetSocketAddress);
As soon as the other device sends udp messages to myIpAddress, my service receives them. It always works, even when the device is off (screen off, not shut down).
The following code only works if the devices screen is on:
InetSocketAddress inetSocketAddress = new InetSocketAddress(InetAddress.getByName("255.255.255.255"), udpPort);
DatagramSocket socket = new DatagramSocket(null);
socket.setReuseAddress(true);
socket.bind(inetSocketAddress);
If the device is inactive (screen off) the service still runs but the udp messages aren't received. I think, Android prevents broadcast messages from receiving them by the device if it is inactive. Is there any possibility to receive them anyway?