I'm encountering a strange problem when working with UDP in Java. Setup: My Android device is initializing the communication, it is connected via Wifi. My computer runs a server written in Java (JRE: 1.8) and is connected via Ethernet.
I'm sending an UDP packet from an Android device to my computer:
address = InetAddress.getByName("192.168.178.57");
packet = new DatagramPacket(data, data.length, address, 61010);
socket.send(packet);
There is no exception thrown while sending the packet. Having Wireshark opened on my computer, I can see the UDP packet being received:
In my server application I'm trying to receive this UDP packet:
address = InetAddress.getByName("192.168.178.57");
socket = new DatagramSocket(61010, address);
byte[] receiveBuffer = new byte[4096];
System.out.println("listening on " + socket.getLocalAddress().getHostAddress() + ":" + socket.getLocalPort() + "...");
// => listening on 192.168.178.57:61010...
packet = new DatagramPacket(receiveBuffer, receiveBuffer.length);
socket.receive(packet);
System.out.println("UDP message received");
However, it is not received: UDP message received is never being printed.
[edit]
The firewall should be configured to allow the packets (ufw allow 61010/udp). There is no security manager in Java that would drop the packet (System.getSecurityManager() is null). But if I send the UDP packet via the server application, instead of the Android device, it is received.
[/edit]
I am pretty sure that this code worked a couple of months ago and that I didn't work on it in between.
What am I missing, any ideas?

sudo ufw allow 61010/udp, with no effect. - Sebastian SchlichtDatagramSocketconstructor that takes only the port as an argument. - John BollingerDatagramSocket.receive()note that "If there is a security manager, a packet cannot be received if the security manager's checkAccept method does not allow it." It is thus possible that your security policy interferes with receiving anything. This is also an area that could have changed. - John Bollinger