Domanda

I use below code to get bonjour service:

try {
    jmdns = JmDNS.create();
    ddServiceListener(type, listener = new ServiceListener() {
        public void serviceResolved(ServiceEvent ev) {
            System.out.println("Service resolved: "
            + ev.getInfo().getQualifiedName()
        + " port:" + ev.getInfo().getPort());
        }
        public void serviceRemoved(ServiceEvent ev) {
        }
    public void serviceAdded(ServiceEvent event) {
        jmdns.requestServiceInfo(event.getType(), event.getName(), 1);
    }
    });
}
catch(Exception e) {
    e.printStackTrace();
}

It can find the device, but I don't now how to get their ip address.
How can I do this?

È stato utile?

Soluzione

Do you find Hostname and Port? If it is,then try to resolve the Hostname to an IP address with InetAddress.
If InetAddress.getByName(hostName) don't work, then try with InetAddress.getAllByName(hostName).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top