BonjourConnect
BonjourConnect
wraps the boilerplate code that's needed to find a service on a network.
Installation
Add jitpack
to your repositories
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
...
}
Add this dependency to your app build.gradle:
implementation 'com.github.grumpyshoe:android-module-bonjourconnect:1.0.1'
Usage
Get instance of BonjourConnect:
val bonjourConnect: BonjourConnect by lazy { BonjourConnectImpl(applicationContext) }
Start search for the network service type you are looking for:
bonjourConnect.getServiceInfo(
type = "_my_service_type._tcp.",
onServiceInfoReceived = { networkService ->
...
},
onError = { errorType ->
...
})
If the requested service is found the functin located at onServiceInfoReceived
is invoked with a parameter of type NetworkService. The object contains detail information about name, type, host and port. of the service/server.
If no service is found within 5 seconds (default timeout) the function located at onError
is invoked with a parameter of type BonjourConnect.ErrorType.
Customize
Timeout
If you want to in- or decrease the timeout you can define the delay in milliseconds at parameter searchTimeout
:
bonjourConnect.getServiceInfo(
type = "_my_service_type._tcp.",
onServiceInfoReceived = { networkService ->
...
},
onError = { errorType ->
...
},
searchTimeout = 5000L)
Need Help or something missing?
Please submit an issue on GitHub.
License
This project is licensed under the terms of the MIT license. See the LICENSE file.
Build Environment
Android Studio 3.4
Build #AI-183.5429.30.34.5452501, built on April 10, 2019
JRE: 1.8.0_152-release-1343-b01 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.14