Pergunta

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?

Foi útil?

Solução

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).

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top