Skip to content

Latest commit

 

History

History
47 lines (36 loc) · 1.71 KB

README.md

File metadata and controls

47 lines (36 loc) · 1.71 KB

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