Search code examples
androidwifizeroconfjmdns

Locate services using Zeroconf with JmDNS on local device AP(hotspot)


With my android device set up as a hotspot/Access point(AP), how can I use JmDNS(3.4.0) to find other devices connected to this AP?

Using a regular AP everything works fine when creating the JmDNS instance the normal way;

jmdns = JmDNS.create();

But using my device as an AP this throws exception.

    java.net.SocketException: No such device
    at org.apache.harmony.luni.platform.OSNetworkSystem.setSocketOption(Native Method)
    at dalvik.system.BlockGuard$WrappedNetworkSystem.setSocketOption(BlockGuard.java:382)
    at org.apache.harmony.luni.net.PlainDatagramSocketImpl.setOption(PlainDatagramSocketImpl.java:198)
    at org.apache.harmony.luni.net.PlainDatagramSocketImpl.join(PlainDatagramSocketImpl.java:137)
    at java.net.MulticastSocket.joinGroup(MulticastSocket.java:190)
    at javax.jmdns.impl.JmDNSImpl.openMulticastSocket(JmDNSImpl.java:459)
    at javax.jmdns.impl.JmDNSImpl.<init>(JmDNSImpl.java:420)
    at javax.jmdns.JmDNS.create(JmDNS.java:60)

I've also tried creating the JmDNS instance with the local IP

jmdns = JmDNS.create( InetAddress.getByName("192.168.1.1") );

which just throws the same exception.

How can I make JmDNS find services connected to the local AP?


Solution

  • It is not possible to use multicast on a local hotspot since it's not possible to acquire the multicast lock. Thus JmDNS will not work.

    For anyone else having this problem, the alternative solution of finding connected devices I ended up using is based on parsing /proc/net/arp