Search code examples
androidnsd

Android NSDService discovery onServiceResolved get wrong port number


I have a problem of getting the registered services port numbers. Actually my application registers a service with port xxxx (e.g 40206), and the registration is done successfully. On the other device, when I registered discovery to discover all of the registered services, I found the service successfully with a valid Host name, but wrong port number, it always returns port 41.

@Override
public void onServiceResolved(NsdServiceInfo serviceInfo) {
    Log.d(TAG, serviceInfo.getPort());
}

Any help why it happens and how to solve it?


Solution

  • using the google NSD service sample code is using a default port "41" in the NSDHelper class, so you have to make sure the you are passing the correct port number to the registerService(Port) function.