An Rx wrapper around the Android NsdManager api.
You can find this library on MavenCentral
implementation 'com.ToxicBakery.library.nsd.rx:android-nsd-rx:3.+'
The NsdManagerRx can be created with a context instance.
NsdManagerRx.fromContext(context)
The service name used is defined in rfc6763 and finds all services without filtering. ietf.org/rfc/rfc6763.txt
NsdManagerRx(context)
.discoverServices(DiscoveryConfiguration("_services._dns-sd._udp"))
.subscribe { event: DiscoveryEvent -> Log.d("Discovery", "${event.service.serviceName}") }
NsdManagerRx(context)
.registerService(RegistrationConfiguration(port = 12345))
.subscribe { event: RegistrationEvent ->
Log.d("Registration", "Registered ${event.nsdServiceInfo.serviceName}")
}
NsdManagerRx(context)
.resolveService(serviceInfo)
.subscribe { event: ResolveEvent ->
Log.d("Resolve", "Resolved ${event.nsdServiceInfo.serviceName}")
}
Discovery and registration return binders in their events. The binders allow the internal listener to be unregistered without disposing the observable. This is important if you want to receive the unregister and stop events from the Android NsdManager. Alternately, disposing of the observables will unregister the internal listeners.
The demo app provides a quick way to run the NSD service against your connected network.