JmDNS: Can't resolve service

前端 未结 2 1218
一生所求
一生所求 2021-02-06 09:06

I\'m trying to implement JmDNS discovery for communication between an Android app and a desktop application. I have followed the following tutorial: http://home.heeere.com/tech-

2条回答
  •  渐次进展
    2021-02-06 09:13

    Use JmDNS.create(InetAddress addr, String name) instead of JmDNS.create(). In more recent versions of Android, JmDNS needs to know more about the local device and the network interface it is listening on.

    JmDNS jmdns; // somewhere global
    
    // In a background thread 
    public void buildJmDNS() {
        InetAddress addr = InetAddress.getLocalHost();
        String hostname = InetAddress.getByName(addr.getHostName()).toString();
        try {
            jmdns = JmDNS.create(addr, hostname); // throws IOException
        } catch (IOException e) {
           e.printStackTrace(); // handle this if you want
        }
    }
    

    I had the same issue you are experiencing and this solved it for me. I have tried to find the example I had found that shows why this is necessary, but I cannot.

提交回复
热议问题