The EasyNSD library allows for easy integration of network service discovery into your app.
Include the below dependencies in your build.gradle
project.
buildscript {
repositories {
google()
maven { url "https://newtronlabs.jfrog.io/artifactory/libs-release-local" }
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.4'
classpath 'com.newtronlabs.android:plugin:5.0.2'
}
}
allprojects {
repositories {
google()
maven { url "https://newtronlabs.jfrog.io/artifactory/libs-release-local" }
}
}
subprojects {
apply plugin: 'com.newtronlabs.android'
}
In the build.gradle
for your app.
dependencies {
compileOnly 'com.newtronlabs.easynsd:easynsd:1.0.1-alpha01'
}
In order to discover services we obtain a cient and call discoverServices with the service type to discover.
// Search for services for 5 seconds
EasyNsd.with(this).discoverServices(serviceType = "_ipp._tcp.", timeout = 5 * 1000L).await()
To register a service.
val serviceInfoNsd = EasyNsdServiceInfo().apply {
setServiceName("EasyNsd")
setServiceType("_ipp._tcp.")
setPort(1234)
}
// Note: This is a blocking call, user the callback if async behavior is desired.
val serviceInfo = EasyNsd.with(this@MainActivity).registerService(serviceInfoNsd).await()
Once a service is found it can be resolved by calling resolveService with the service information object found.
val resolvedService = EasyNsd.with(this@MainActivity).resolveService(foundServiceInfoNsd).await()
Please support the continued development of these libraries. We host and develop these libraries for free. Any support is deeply appriciated. Thank you!
BTC Address: 39JmAfnNhaEPKz5wjQjQQj4jcv9BM11NQb
https://gist.github.com/NewtronLabs/216f45db2339e0bc638e7c14a6af9cc8