问题描述
尝试启动多播提供程序时获取java.net.SocketException
:
Getting java.net.SocketException
when trying to start a multicast provider:
2013-09-11 11:45:44,204 [main] ERROR net.sf.ehcache.distribution.MulticastRMICacheManagerPeerProvider: Error starting heartbeat. Error was: Can't assign requested address
java.net.SocketException: Can't assign requested address
at java.net.PlainDatagramSocketImpl.join(Native Method)
at java.net.AbstractPlainDatagramSocketImpl.join(AbstractPlainDatagramSocketImpl.java:178)
at java.net.MulticastSocket.joinGroup(MulticastSocket.java:319)
at net.sf.ehcache.distribution.MulticastKeepaliveHeartbeatReceiver.init(MulticastKeepaliveHeartbeatReceiver.java:88)
at net.sf.ehcache.distribution.MulticastRMICacheManagerPeerProvider.init(MulticastRMICacheManagerPeerProvider.java:95)
推荐答案
这是由java.net.NetworkInterface.getDefault()
返回的IPv6地址引起的.我在Macbook上并且正在使用无线功能-p2p0(用于AirDrop)已作为默认网络接口返回,但我的p2p0仅具有一个IPv6 ether
项(通过运行ipconfig
找到).
This was caused by an IPv6 address being returned from java.net.NetworkInterface.getDefault()
. I'm on a Macbook and was using wireless -- p2p0 (used for AirDrop) was returned as the default network interface but my p2p0 only has an IPv6 ether
entry (found by running ipconfig
).
两种解决方案都对我有用(我更喜欢第一种,因为无论您使用有线还是无线连接都可以使用)
Two solutions, both of which worked for me (I prefer the first because it works whether you are using a wired or wireless connection)
- 使用
-Djava.net.preferIPv4Stack=true
启动JVM.这导致java.net.NetworkInterface.getDefault()
返回我的vboxnet0网络接口-不知道如果不运行仅限主机的VM,将会得到什么. - 关闭无线并使用有线连接
- Start the JVM with
-Djava.net.preferIPv4Stack=true
. This causedjava.net.NetworkInterface.getDefault()
to return my vboxnet0 network interface -- not sure what you'll get if you're not running a host-only VM. - Turn off wireless and use a wired connection
这篇关于使用Ehcache多播获取“无法分配请求的地址" java.net.SocketException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!