Java DatagramSocket is able to receive packets on windows, but not linux

Note that the poster seems to have an issue related to mine in this thread: DatagramSocket Broadcast Behavior (Windows vs. Linux) Unfortunately this post died without any solution to the problem.

I am currently having problems with Datagramsockets in Java. In general the problem is that I have a piece of Java code that is capable of accepting packages on Windows, but not Linux.

It is very important that my application

  • Ability to work with both Windows and Linux. We can say that we only support Windows 7 and later.
  • Works on machines with multiple network interfaces. By this I mean that it should be possible to specify which network interface the application should receive from its packets.

My test machines

  • m1: Running Windows 7 Pro x64 on a physical computer. java version "1.8.0_45" (Oracle)
  • m2: Running centos7 x64 in vmware. Using java version "1.8.0_51" (Oracle)
  • m3: Runnning fedora 19 x64 on a physical machine. Using java version 1.7.0_71 (openjdk)
  • m4: Runnning fedora 19 x64 in vmware. java version "1.8.0_31"
  • m5: Running WindowsXP x86 on a physical machine: This machine is not running my program, but instead an external system that is translating the packages I want to receive.
  • m6: Running Windows 7 Pro x64 on a physical computer: This machine won't run my program, nor does the external system transmitting the packets I want to receive.

Currently my program receives packages from m5 and m6 to m1, but not m2, m3 and m4.

In general, the socket logic in my program can be described as follows

// Setting up the socket
DatagramSocket socket = new DatagramSocket(networkInterfaceAddress, port);
socket.setReceiveBufferSize(90000);

// Setting up the receive packets
DatagramPacket packet = new DatagramPacket(new byte[1], 0);

// Constructing the receive buffer
buffer = new byte[1024]


// Receiving the packet
packet.setData(buffer);
packet.setLength(buffer.length);
socket.receive(packet);

      

I've tried the following:

  • Disable firewall on all machines. It did not help
  • Used by Wireshark on m2, m3 and m4. Wireshark was able to detect packets on all machines, so they actually receive them (4. also indicates this)
  • Changed my test setup st I was streaming from m2 instead (using my own app, not an external system). Neither m1, m3 nor m4 was able to receive packages. The funny thing is that I was able to see them in external systems on m5 and m6.
  • Rewrote the st logic I did not specify networkInterfaceAddress in the constructor for the DatagramSocket (so I used socket = new DatagramSocket (port);. With this update I was unexpectedly able to get packets on m2, m3 and m4

4 seems to indicate that the problem is with networkInterfaceAddress, but if I try to run the program in debug mode, I see that networkInterfaceAddress does indeed contain the expected value. Of course I also tried hardcodet dummy code example on m2. In this example Dummy I

  • Used by ifconfig to view my network interface address. In my case, ifconfig gave me init 10.10.1.41
  • Used by networkInterfaceAddress = InetAddress.getByName ("10.10.1.41");

Even with this hardcodet network interface, I was unable to get the packages.

Therefore, I can currently only receive packets on Linux without exposing a network interface to the DatagramSocket constructor. The problem with this solution is that (as far as I understand) it will result in the application being unable to receive packets only from a specific network interface.

To be honest, I am running out of ideas, so I hope someone can help me solve this problem.

+3


source to share





All Articles