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?

animuson
  • 53,861
  • 28
  • 137
  • 147
Petrus
  • 2,611
  • 3
  • 21
  • 21
  • Is there no name server on that AP? – Earl Aug 09 '11 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 Aug 09 '11 at 13:31
  • @Pterus did you manage to get round this? – zaf Oct 31 '11 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 Oct 31 '11 at 20:06

3 Answers3

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

Petrus
  • 2,611
  • 3
  • 21
  • 21
  • 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 Jan 18 '14 at 16:32
  • Hi can you share the implementation of the alternate way that you came up with? – Phani Rithvij Apr 13 '20 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? – Phani Rithvij Apr 14 '20 at 03: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 Apr 16 '20 at 09: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

Pawel
  • 11
  • 1
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.

Jim Cortez
  • 471
  • 5
  • 19