I'm attempting to use Java to find a SLP service named test, that is running on my network and create a connection to it. I know the service is running and can use the command "slptool findsrvs service:test" to find it. This command returns "service:test://192.168.1.4:12345,65535". However the following code:
import java.util.Locale;
import ch.ethz.iks.slp.*;
public class OpenConnection {
public static void main(String[] args) throws ServiceLocationException {
Locator locator = ServiceLocationManager.getLocator(new Locale("en"));
ServiceLocationEnumeration sle = locator.findServices(new ServiceType("service:test"), null, null);
System.out.println("Looking up ...");
System.out.println(sle.nextElement());
while (sle.hasMoreElements()) {
ServiceURL foundService = (ServiceURL) sle.nextElement();
System.out.println(foundService);
}
System.out.println("Finished.");
}
}
produces the following output:
java.net.SocketException: bad argument for IP_MULTICAST_IF: address not bound to any interface
at java.net.PlainDatagramSocketImpl.socketSetOption(Native Method)
at java.net.AbstractPlainDatagramSocketImpl.setOption(AbstractPlainDatagramSocketImpl.java:299)
at java.net.MulticastSocket.setInterface(MulticastSocket.java:448)
at ch.ethz.iks.slp.impl.SLPCore.<clinit>(SLPCore.java:279)
at OpenConnection.main(OpenConnection.java:7)
Looking up ...
null
Finished.
I'm assuming the null is printed for the print sle.nextElement() statement due to the failure of the locator look up in line 7:
Locator locator = ServiceLocationManager.getLocator(new Locale("en"));
So my question is does anyone know why a bad argument for IP_MULTICAST_IF could cause this and how to fix it? And if someone sees something that could be causing a problem other than the IP_MULTICAST_IF please feel free to point it out.
On a side note if it helps to know I am using JavaSE-1.6, jslp-0.7.1, and commons-loggin-1.1.1 libraries on Ubuntu 11.04.
I just ran into the same issue. What fixed it for me was doing a
System.setProperty("java.net.preferIPv4Stack", "true")
at startup, which can also be done by adding the following argument to the java cmd line instead.
-Djava.net.preferIPv4Stack=true