Java UDP问题
我正在运行一个 UDP 客户端,它侦听多播 ip 230.10.10.10 、端口 11111 的消息。如果我在与 UDP 广播器相同的服务器中运行客户端 java 代码,我就能够接收 UDP 消息。但是,如果我在同一域中的另一台服务器上运行它,我不会收到任何消息。
我正在使用 Windows Server 2008。请让我知道如何调试它?
I am running a UDP client that listens to the multicast ip 230.10.10.10 , port 11111 for messages. IF I run the client java code in the same server as the UDP broadcaster, I am able to receive the UDP message. However, if I run it in another server in the same domain, I am not getting any messages.
I am using windows server 2008. Kindly let me know how to debug it ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先,UDP 不是有保证的传送协议。
其次,UDP 数据包可能在您的网络上受到防火墙或过滤。
您可以通过端口 11111 从客户端计算机连接到服务器计算机吗?
firstly, UDP is not a guaranteed delivery protocol.
secondly, the UDP packets could be firewalled or filtered on your network.
can you connect from the client machine to the server machine on port 11111?
谢谢各位的帮助,我现在已经解决了。解决方案是在侦听器中调用 setInterface() 方法。
广播者是多宿主的,有两个 IP 地址,侦听器有一个 IP。因此,当我在 setInterface 方法中设置侦听器 IP 时,它工作得很好。
但我仍然不确定这是如何工作的,因为 setInterface 方法是在广播器中调用的,因为它是多宿主的,没关系。但为什么还需要在监听器中设置它呢? 。任何建议都会有所帮助。
Thanks for the help guys.I have it resolved now. The solution was to call the setInterface() method in the Listener
The broadcaster is multihomed, having two IP addresses and the listener has a single IP.So, when I set the listener IP in the setInterface method, it worked fine.
But I am still not sure how this works though, because the setInterface method is called in the broadcaster as it is multihomed and thats okay. But why is it necessary to set it in the listener also ? . Any advice will be helpful.
问题也可能是多播数据包的 TTL。如果为0则只能在本地接收包裹。我建议您使用 Wireshark 等工具检查网络流量。如果这是问题所在,请将 TTL 值增加到 32。您可能还需要设置
-Djava.net.preferIPv4Stack=true
。The problem might also be the TTL of the multicast packets. If it's 0 then the packages can only be received locally. I'd recommend you to inspect the network traffic with a tool like Wireshark. If that's the problem, increase the TTL value to 32. You might also need to set
-Djava.net.preferIPv4Stack=true
.