I'm trying to get the mHost of the NsdServiceInfo passed as parameter to NsdManager.DiscoveryListener.onServiceFound() but it's null. I have two android devices where device 1 is the server and device 2 is the client.
This is how I register the server in the device 1
public void registerService(int port, InetAddress myIp) {
NsdServiceInfo serviceInfo = new NsdServiceInfo();
serviceInfo.setPort(port);
serviceInfo.setServiceName(this.serviceName);
serviceInfo.setServiceType(SERVICE_TYPE);
serviceInfo.setHost(myIp);
this.nsdManager.registerService(
serviceInfo, NsdManager.PROTOCOL_DNS_SD, registrationListener);
}
And this is how I initialize the DiscoveryListener
public void initializeDiscoveryListener() {
discoveryListener = new NsdManager.DiscoveryListener() {
@Override
public void onServiceFound(NsdServiceInfo service) {
Log.d(TAG, "Service discovery success" + service);
if (!service.getServiceType().equals(SERVICE_TYPE)) {
Log.d(TAG, "Unknown Service Type: " + service.getServiceType());
} else if (service.getHost() == myIp) {
Log.d(TAG, "Same machine: " + service.getHost());
} else if (service.getServiceName().contains(serviceName)){
nsdManager.resolveService(service, resolveListener);
}
}
...
}
}
But service.getHost() returns null.
Any suggestion?