通过Java发送UDP数据包
我正在尝试通过笔记本电脑的以太网电缆将 UDP 数据包从我的 PC 发送到 FPGA。我一直在使用Java的DatagramPacket和DatagramSocket来发送UDP数据包。但是,这些数据包只会通过我的笔记本电脑的无线接口发送。如何指定数据包应通过我的以太网接口?
谢谢。
I'm trying to send UDP packets from my PC to an FPGA via my laptop's ethernet cable. I've been using Java's DatagramPacket and DatagramSocket to send the UDP packets. However, these packets will only send over my laptop's wireless interface. How can I specify that the packets should go through my ethernet interface?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当然,您可以按照x4u的建议将DatagramSocket绑定到特定接口,但是如果您的UDP数据包发送到不正确的接口上,我宁愿假设您的操作系统网络堆栈的路由表配置不正确,因此操作系统相信您的 FPGA 可以通过 WLAN 接口而不是以太网接口访问。
You may of course bind your DatagramSocket to a specific interface as x4u suggested, but if your UDP packets are sent on an incorrect interface, I would rather assume that the routing table of your operating system's network stack is configured incorrectly, so that the operating system believes your FPGA to be reachable through the WLAN interface instead of your ethernet interface.
如果使用 public DatagramSocket(int port, InetAddress laddr) 构造函数来创建 DatagramSocket 并将其传递给本地以太网接口的 InetAddress,也许它会起作用。
Maybe it works if use the
public DatagramSocket(int port, InetAddress laddr)
constructor to create your DatagramSocket and pass it the InetAddress of your local ethernet interface.