1

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?

4
  • Is there no name server on that AP?
    – Earl
    Commented Aug 9, 2011 at 13:29
  • To clearify, the AP is a hotspot set up on the device I'm running the application on. And I want to find other services connected to this device/AP. It's sort of a workaround for the lack of AdHoc support on android.
    – Petrus
    Commented Aug 9, 2011 at 13:31
  • @Pterus did you manage to get round this?
    – zaf
    Commented Oct 31, 2011 at 13:49
  • No, my current opinion is that it isn't possible. I implemented an alternative procedure of finding clients using ping and arp-lookup by parsing the /proc/net/arp file. It works surprisingly well!
    – Petrus
    Commented Oct 31, 2011 at 20:06

3 Answers 3

1

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

4
  • I have obtained multicast lock android 4.4.2 using android.net.wifi.WifiManager, the lock.isHeld() returns true but jmDNS throws the same exception. Any idea what could be the problem?
    – serine
    Commented Jan 18, 2014 at 16:32
  • Hi can you share the implementation of the alternate way that you came up with? Commented Apr 13, 2020 at 17:19
  • When I try to read the file /proc/net/arp in my android 10 device after requesting storage permissions it says permission denied and filenotfounderror I think it requires root access? Commented Apr 14, 2020 at 3:46
  • @PhaniRithvij I'm sorry, this was 8 years ago. I'm afraid things might have changed since then. Android security model is completely different now. And I dont think I have access to that piece of code I wrote anymore. The file might not be three on android 10, or maybe it has moved, I dont know. Good luck.
    – Petrus
    Commented Apr 16, 2020 at 9:31
1

This is now possible (since API 16) with a help of Android Network Service Discovery (NSD).
NSD supports phone as hotspot/AP as well as regular AP connections (i.e. connection to a router). So you don't need JmDns anymore to achieve your goal.
See: https://developer.android.com/training/connect-devices-wirelessly/nsd

0
0

I don't think this directly answers your question, but I found that unless I have active wifi jmDNS won't work. I had to disable discovery if my wifi is off.

Not the answer you're looking for? Browse other questions tagged or ask your own question.