How to choose a network in a java program that performs udp exchange in Multicast mode

Viewed 21

A Java application transmits data over UDP in Multicast mode with another computer. VirtualBox is installed on the same machine.

Here is the code for sending data:

private final static String IP_ADDR = "224.1.1.201";
DatagramSocket socket;
public void sending() {
    socket = new DatagramSocket();
    group = InetAddress.getByName(IP_ADDR);
    sendingDataBuffer = parserData(dataBuffer);
    DatagramPacket packet 
    = new DatagramPacket(sendingDataBuffer, sendingDataBuffer.length, group, SERVICE_PORT);
    socket.send(packet);
}

The problem turned out to be that the program was sending packets to the VirtualBox network, so I could neither receive them on the receiving side nor see them in Wireshark. How can I specify in the Java code which network to send packets to? If I disconnect the VirtualBox network connection, then packets start to be sent via a standard network connection to another computer.

Why is my app sending data to this particular network?

1 Answers

The problem stems from Microsoft assigning interface Metrics based on the driver's own reported Link speed in Windows 7. Since that's all 1GB, there is a clash on metric.

Here is the solution that helped me:

  1. Open up Network and Sharing Center
    • Click 'Change Adapter Settings'
    • Right click 'VirtualBox Host-Only Network', go to Properties
  2. Double click "Internet Protocol Version 4 (TCP/IPv4)' under 'This connection uses the following items'.
  3. In the Properties page, click "Advanced..."
  4. In the "Advanced TCP/IP Settings", tab "IP Settings", uncheck the box marked "Automatic Metic" and type in 800 or higher.
Related