项目作者: ToxicBakery

项目描述 :
Android Network Service Discovery Rx
高级语言: Kotlin
项目地址: git://github.com/ToxicBakery/Android-Nsd-Rx.git
创建时间: 2017-11-23T15:13:13Z
项目社区:https://github.com/ToxicBakery/Android-Nsd-Rx

开源协议:Apache License 2.0

下载


Android Network Service Discovery Rx

CircleCI
Central

An Rx wrapper around the
Android NsdManager api.

Install

You can find this library on MavenCentral

  1. implementation 'com.ToxicBakery.library.nsd.rx:android-nsd-rx:3.+'

Creating a Manager

The NsdManagerRx can be created with a context instance.

  1. NsdManagerRx.fromContext(context)

Discovery

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

  1. NsdManagerRx(context)
  2. .discoverServices(DiscoveryConfiguration("_services._dns-sd._udp"))
  3. .subscribe { event: DiscoveryEvent -> Log.d("Discovery", "${event.service.serviceName}") }

Register

  1. NsdManagerRx(context)
  2. .registerService(RegistrationConfiguration(port = 12345))
  3. .subscribe { event: RegistrationEvent ->
  4. Log.d("Registration", "Registered ${event.nsdServiceInfo.serviceName}")
  5. }

Resolve

  1. NsdManagerRx(context)
  2. .resolveService(serviceInfo)
  3. .subscribe { event: ResolveEvent ->
  4. Log.d("Resolve", "Resolved ${event.nsdServiceInfo.serviceName}")
  5. }

Binders

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.

Demo App

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

Demo Application Screenshot