0

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?

user3137385
  • 315
  • 5
  • 14
  • Have you any progress on it? I got stuck with the same problem. – Pepa Chmel Jan 14 '17 at 15:53
  • I'm doing it without broadcast. Anyway, the android device doesn't receive any messages if it is off for a longer time even if a message is sent to its own ip address (not broadcast). The problem is that the devices processor goes down if not used. So the solution is to keep the device awake. That's what I'm doing but there is a big disadvantage: Keeping awake costs lots of energy. – user3137385 Jan 15 '17 at 16:23

0 Answers0