Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting `Can't assign requested address` java.net.SocketException using Ehcache multicast

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) 
like image 290
eebbesen Avatar asked Sep 11 '13 17:09

eebbesen


2 Answers

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)

  1. Start the JVM with -Djava.net.preferIPv4Stack=true. This caused java.net.NetworkInterface.getDefault() to return my vboxnet0 network interface -- not sure what you'll get if you're not running a host-only VM.
  2. Turn off wireless and use a wired connection
like image 91
eebbesen Avatar answered Sep 21 '22 21:09

eebbesen


A slight variation on the accepted answer: You can also add the following line of code to your java code:

System.setProperty("java.net.preferIPv4Stack", "true"); 
like image 36
user3697700 Avatar answered Sep 19 '22 21:09

user3697700