Network Service Discovery: empty NsdServiceInfo in onServiceRegistered()-Callback of the RegistrationListener

267 Views Asked by At

When I register a service, following the guidelines from android developers, the NsdServiceInfo-Object does not contain all the information it should contain after the service was registered.

mRegistrationListener = new NsdManager.RegistrationListener() {

  @Override
  public void onServiceRegistered(NsdServiceInfo _NsdServiceInfo) {
  Log.i(TAG, "Service registered: "+_NsdServiceInfo);
  }

[...]

}

So when the onServiceRegistered()-callback is fired (that should only be, if the service was successfully registered) the log-message says:

Service registered: name: LTCServer_Niklas' Galaxy A3, type: null, host: null, port: 0, txtRecord: 

So the, for the registration inserted, type (-http.-tcp.) was deleted and there is no host or port in the _NsdServiceInfo. This could not be correct.

This happens on various devices with various android-versions.

Does someone have an explanation about this?

1

There are 1 best solutions below

0
On

You should use underscores instead of hyphens (-http.-tcp.) in your service type eg: _http._tcp.

The syntax is "_<protocol>._<transportlayer>".

https://developer.android.com/training/connect-devices-wirelessly/nsd#register