如何在Java程序中选择网络,该程序以多播模式执行UDP交换

发布于 2025-01-30 07:41:56 字数 651 浏览 1 评论 0原文

Java应用程序通过另一台计算机在多播模式下通过UDP传输数据。 VirtualBox安装在同一台计算机上。

这是发送数据的代码:

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);
}

事实证明,该程序将数据包发送到VirtualBox网络,因此我既不能在接收方接收它们,也无法在Wireshark中看到它们。如何在Java代码中指定哪个网络将数据包发送到? 如果我断开VirtualBox网络连接的连接,则可以通过标准网络连接发送到另一台计算机来发送数据包。

为什么我的应用程序将数据发送到此特定网络?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

护你周全 2025-02-06 07:41:56

该问题源于Microsoft基于Windows 7中驾驶员自己报告的链接速度分配接口指标。由于这是全部1GB,因此公制上有一场冲突。

这是帮助我的解决方案:

  1. 开设网络和共享中心
    • 单击“更改适配器设置”
    • 右键单击“虚拟盒主机网络”,转到properties
  2. 双击“ Internet协议版本4(TCP/IPV4)”下的“此连接使用以下项目”。
  3. 在“属性”页面中,单击“高级” ...
  4. 在“高级TCP/IP设置”中,TAB“ IP设置”,取消选中标记为“自动METIC”的盒子,并以800或更高的形式键入。

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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文