MulticastSocket 失败后未响应
尝试在 MulticastSocket 上调用 joinGroup(addr) 时出现 SocketException。 这种情况仅发生在我们设置为在机器启动时自动启动应用程序的 Windows 机器上。
似乎抛出异常是因为 Windows 尚未完全完成其启动过程,这是异常。
java.net.SocketException: error setting options
at java.net.PlainDatagramSocketImpl.join(Native Method)
at java.net.PlainDatagramSocketImpl.join(Unknown Source)
at java.net.MulticastSocket.joinGroup(Unknown Source)
在我们的应用程序启动时,如果我们在尝试加入该组之前等待一分钟,一切都会正常。
因此,我们决定放入一个重试循环,以便在网络可用时立即连接,这似乎可以工作。 两次失败后,第三次加入该组的尝试成功了。
问题是,现在 MulticastSocket 没有收到来自该组的任何消息,即使它加入得很好。
我在每次失败后创建一个新的 MulticastSocket 并丢弃旧的。
为什么在一个 MulticastSocket 上加入组失败会影响没有任何错误地加入的组,我该如何解决这个问题?
I get a SocketException when trying to call joinGroup(addr) on MulticastSocket. This is only happening on a Windows machine that we have setup to auto start our appliction when the machine is booted up.
It seems like the exception is thrown because Windows has not completely finished its startup process and here is the exception.
java.net.SocketException: error setting options
at java.net.PlainDatagramSocketImpl.join(Native Method)
at java.net.PlainDatagramSocketImpl.join(Unknown Source)
at java.net.MulticastSocket.joinGroup(Unknown Source)
On startup of our app, if we wait a minute before trying to join the group, everything works fine.
So we decided to put in a retry loop so that it will connect as soon as the network is available which seemed to work. After two failures, the third attempt to join the group works.
The problem is, now the MulticastSocket does not receive any messages from the group, even though it joined up fine.
I am creating a new MulticastSocket after each failure and discarding the old one.
Why would a failure to join the group on one MulticastSocket affect the one that joined without any errors, and how could I possibly work around this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我从来没有找出为什么套接字在成功加入组后不会收到消息。 不过,我确实想出了一个解决方法。
我循环检查所有网络接口,并确保列表中有一个有效的网络接口并且它已启动并正在运行。 我要做的下一件事是尝试在 MulticastSocket 上设置该网络接口。 如果这些测试通过,那么我让套接字尝试加入该组。 这似乎有效,但我仍然想了解更多幕后发生的事情。
I never did find out WHY the socket would not recieve messages after joining the group successfully. I did come up with a work around, however.
I loop through all the network interfaces and make sure there is a valid one in the list and it is up and running. The next thing I do is try setting that network interface on a MulticastSocket. If these tests pass, then I let the socket try to join the group. It seems to work, but I still would like to know more about what is going on behind the scenes.
我知道这已经很旧了,但是可靠的多播答案似乎很少见。
我认为你会更好:
因为这更简洁,并且还可以确保获得一个实际上会接收多播消息的NIC。
I know this is old, but solid multicast answers seem rare.
I think you would be better off with:
As this is more succinct and would also ensure that are getting a NIC that will actually be receiving the multicast message.