组播通信出现Can't assign requested address
的SocketException
异常
报错信息如下:
java.net.SocketException: Can't assign requested address
at java.net.PlainDatagramSocketImpl.join(Native Method)
at java.net.AbstractPlainDatagramSocketImpl.join(AbstractPlainDatagramSocketImpl.java:179)
at java.net.MulticastSocket.joinGroup(MulticastSocket.java:323)
at net.yuxianghe.Listener.main(Listener.java:21)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Process finished with exit code 0
解决方案:
启动的时候VM options加入: -Djava.net.preferIPv4Stack=true
或者去配置一个ipv6的组播地址.
这样问题就解决了。