Open 4ndre opened 4 years ago
I fixed this bug myself. The group join call uses the wrong initiator. It should be
this.bonjourBrowser = JmDNS.create(deviceIpAddress,"RetoWlanBrowser");
whereas
InetAddress deviceIpAddress =getLocalIpAddress();
coming from this function:
public InetAddress getLocalIpAddress() {
try {
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
NetworkInterface intf = en.nextElement();
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress()
&& (inetAddress.getAddress().length == 4)) {
System.out.println("IP: "+ inetAddress.getHostAddress() );
return inetAddress;
}
}
}
} catch (SocketException ex) {
System.out.println("IP address not found: "+ ex.toString());
}
return null;
}
Furthermore, I needed to compile jmDNS 0.5.7 to fix a bug with the older version included in jReto (see https://github.com/jmdns/jmdns/issues/120). Maybe you can implement this in the next release.
I got the communication mostly working, some weird quirks, but the most important use case was using the comm on a local mobile hotspot for fast data transfer. Initially it worked somehow, but now I get reproducibly an error:
2020-10-19 15:56:16.191 18658-18738/se.cevt.carftserv W/HostInfo: Could not find any address beside the loopback.
2020-10-19 15:56:16.197 18658-18738/se.cevt.carftserv W/System.err: java.net.SocketException: setsockopt failed: ENODEV (No such device)
2020-10-19 15:56:16.197 18658-18738/se.cevt.carftserv W/System.err: at libcore.io.IoBridge.setSocketOption(IoBridge.java:377)
2020-10-19 15:56:16.198 18658-18738/se.cevt.carftserv W/System.err: at java.net.PlainDatagramSocketImpl.join(PlainDatagramSocketImpl.java:184)
2020-10-19 15:56:16.198 18658-18738/se.cevt.carftserv W/System.err: at java.net.AbstractPlainDatagramSocketImpl.join(AbstractPlainDatagramSocketImpl.java:199)
2020-10-19 15:56:16.198 18658-18738/se.cevt.carftserv W/System.err: at java.net.MulticastSocket.joinGroup(MulticastSocket.java:325)
2020-10-19 15:56:16.198 18658-18738/se.cevt.carftserv W/System.err: at javax.jmdns.impl.JmDNSImpl.openMulticastSocket(JmDNSImpl.java:463)
2020-10-19 15:56:16.198 18658-18738/se.cevt.carftserv W/System.err: at javax.jmdns.impl.JmDNSImpl.<init>(JmDNSImpl.java:420)
2020-10-19 15:56:16.198 18658-18738/se.cevt.carftserv W/System.err: at javax.jmdns.JmDNS.create(JmDNS.java:102) 2020-10-19 15:56:16.198 18658-18738/se.cevt.carftserv W/System.err: at de.tum.in.www1.jReto.module.wlan.WlanBrowser.startBrowsing(WlanBrowser.java:59)
2020-10-19 15:56:16.198 18658-18738/se.cevt.carftserv W/System.err: at de.tum.in.www1.jReto.routing.managed_module.ManagedBrowser.attemptStart(ManagedBrowser.java:35)
2020-10-19 15:56:16.198 18658-18738/se.cevt.carftserv W/System.err: at de.tum.in.www1.jReto.routing.managed_module.ManagedBrowser.lambda$new$15$ManagedBrowser(ManagedBrowser.java:25)
2020-10-19 15:56:16.198 18658-18738/se.cevt.carftserv W/System.err: at de.tum.in.www1.jReto.routing.managed_module.-$$Lambda$ManagedBrowser$72ob9WPjc_eoIvpq-IQm3TI8POA.run(Unknown Source:2)
2020-10-19 15:56:16.198 18658-18738/se.cevt.carftserv W/System.err: at de.tum.in.www1.jReto.util.RetryableActionExecutor.start(RetryableActionExecutor.java:61)
2020-10-19 15:56:16.198 18658-18738/se.cevt.carftserv W/System.err: at de.tum.in.www1.jReto.util.StartStopHelper.start(StartStopHelper.java:53)
2020-10-19 15:56:16.198 18658-18738/se.cevt.carftserv W/System.err: at de.tum.in.www1.jReto.routing.managed_module.ManagedBrowser.startBrowsing(ManagedBrowser.java:82)
2020-10-19 15:56:16.198 18658-18738/se.cevt.carftserv W/System.err: at de.tum.in.www1.jReto.module.util.CompositeBrowser.startBrowsing(CompositeBrowser.java:65)
2020-10-19 15:56:16.198 18658-18738/se.cevt.carftserv W/System.err: at de.tum.in.www1.jReto.routing.DefaultRouter.start(DefaultRouter.java:71)
2020-10-19 15:56:16.198 18658-18738/se.cevt.carftserv W/System.err: at de.tum.in.www1.jReto.LocalPeer.start(LocalPeer.java:202)
2020-10-19 15:56:16.198 18658-18738/se.cevt.carftserv W/System.err: at com.comp.ft.MainActivity$2.run(MainActivity.java:304)
2020-10-19 15:56:16.198 18658-18738/se.cevt.carftserv W/System.err: at java.lang.Thread.run(Thread.java:919)
I googled the issue and it is hard to find solutions, but I suspect that the hotspot is not identified as a network interface and it cannot initialize the peer. Found only one solution when this occurs on multicast (like here), specifying the exact interface: https://stackoverflow.com/questions/33384534/java-net-socketexception-setsockopt-failed-enodev-no-such-device. Not sure that applies here, since I may have a lack of interfaces and not too many. Any ideas?