Skip to content

Network Service Discovery wrapper for Kotlin Flow on Android.

License

Notifications You must be signed in to change notification settings

JBou/android-nsd-flow

 
 

Repository files navigation

Android Network Service Discovery Flow

A Flow wrapper around the Android NsdManager api. If you are using RxJava I would recommend to check out Android Network Service Discovery Rx

Creating a Manager

The NsdManagerFlow can be created with a context instance.

NsdManagerFlow(context)

Discovery

The service name used is defined in rfc6763 and finds all services without filtering. ietf.org/rfc/rfc6763.txt

NsdManagerFlow(context)
    .discoverServices(DiscoveryConfiguration("_services._dns-sd._udp"))
    .flowOn(Dispatchers.IO) // discovering must be done on a different CoroutineContext than main
    .collect { event: DiscoveryEvent -> Log.d("Discovery", "${event.service.serviceName}") }

Register

NsdManagerFlow(context)
    .registerService(RegistrationConfiguration(port = 12345))
    .flowOn(Dispatchers.IO)
    .collect { event: RegistrationEvent -> Log.d("Registration", "Registered ${event.nsdServiceInfo.serviceName}") }

Resolve

NsdManagerFlow(context)
    .resolveService(serviceInfo)
    .flowOn(Dispatchers.IO)
    .collect { event: ResolveEvent -> Log.d("Resolve", "Resolved ${event.nsdServiceInfo.serviceName}") }

Demo App

The demo app provides a quick way to run the NSD service against your connected network.

Demo Application Screenshot

About

Network Service Discovery wrapper for Kotlin Flow on Android.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Kotlin 100.0%