Search code examples
javasocketsnetwork-programmingudppacket-loss

Java DatagramSocket not receiving DatagramPacket (eg. Oracle QuoteServer/-Client)


I tried implementing my own server and client classes in Java which only worked with my desktop as the server, laptop as the client and never with desktop as the client.

This is why I tried using the QuoteServer and QuoteClient classes from Oracle. Same problem. It works only when I run the QuoteServer on my desktop and the QuoteClient on my laptop. The other way around, the client cannot reach the server.

I ran Wireshark both ways and documented the logs. I did not change any code from Oracle except the servers IP in QuoteClient to the IP I ran the servers on.

Working Wireshark log:

  1. UDP as request from client (laptop) to server (desktop)
  2. ARP broadcast request from server (desktop)
  3. ARP reply from client (laptop) to server (desktop)
  4. UDP containing message from server (desktop) to client (laptop)

Not working Wireshark log:

  1. UDP as request from client (desktop) to server (laptop)
  2. ARP request from server (laptop) to client (desktop)
  3. ARP reply from client (desktop) to server (laptop)
  4. nothing

Also the QuoteServer program (laptop) did not receive the UDP request although it shows up in Wireshark.

I am using a TPLink WLan stick with my desktop which shouldn't be the problem.

What can I do to resolve the problem or figure out what exactly the problem is in the first place? Could it be a firewall issue and how do I configure the firewall? (Windows Defender on both devices.)

Greatly appreciate any help as it's really bugging me and I don't know what to try anymore.


Solution

  • Could it be a firewall issue

    If both the client and the server see the original request packet in Wireshark, then it's probably a firewall issue. Windows Defender asks to automatically create a firewall rule the first time an .exe tries to listen for packets, but if that's cancelled, the program remains blocked.

    On the other hand, the fact that there are ARP queries going in the specified direction seems to indicate that the server did try to respond... but it's unclear whether they were actually caused by the request.

    how do I configure the firewall? (Windows Defender on both devices.)

    Run wf.msc on the receiving device. Open "Inbound" and add either a rule that allows java.exe to receive packets (or edit/delete any existing "Deny" rules for java.exe that you may find), or a rule that allows packets to be received to the specific UDP port irrespective of the program.