RxBonjour | ️ THIS PROJECT IS ARCHIVED | HTTP Client library
kandi X-RAY | RxBonjour Summary
kandi X-RAY | RxBonjour Summary
️ THIS PROJECT IS ARCHIVED. No further development is scheduled. A reactive wrapper around network service discovery functionalities for Kotlin and Java.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of RxBonjour
RxBonjour Key Features
RxBonjour Examples and Code Snippets
Community Discussions
Trending Discussions on RxBonjour
QUESTION
I'm using NsdManager in an Android App to discover NSD services published by another device also developed by me. I only do service discovery on Android App (no service registration needed on this side). There are several instances of the same type of service published at the same time on the network.
I started using the sample code provided by Google (https://developer.android.com/training/connect-devices-wirelessly/nsd) but I had fatal errors due to reusing the same resolver object at the same time for more than one service resolution. Then I found several people suggesting to create a new resolver object each time (like in Listener already in use (Service Discovery)).
I did this and the fatal error was replaced by a Resolve Failure error code 3 that meant that the resolve process was active. Better than before, but only the first service was resolved and the rest was ignored due to this failure.
Then I found a person suggesting to give a special treatment to Error Code 3 by resending the resolve request recursively until it eventually becomes resolved ( NSNetworkManager.ResolveListener messages Android).
I implemented this solution in Kotlin and it kind of works but I'm not really satisfied because:
- I believe that I'm creating a lot of additional Resolver objects and I'm not sure if they are later garbage collected or not.
- I'm retrying several times in a loop, maybe causing additional and unnecessary burden on the device and the network. Not sure if I should add a short sleep before invoking service resolution again.
- If there is some network problem, the program may try thousand of times to resolve the same service instead of just abandoning the resolution and waiting for the service to be discovered again.
The people of RxBonjour2 have come with a more complex and robust solution but it's too complex for me to follow it: https://github.com/mannodermaus/RxBonjour/blob/2.x/rxbonjour-drivers/rxbonjour-driver-nsdmanager/src/main/kotlin/de/mannodermaus/rxbonjour/drivers/nsdmanager/NsdManagerDiscoveryEngine.kt
I feel frustrated that Google's official examples do not handle these problems correctly. The nsd_chat sample uses a single resolver object and fails when more than one service with the same type is published at the same type on the network.
Can you suggest a better solution? Or any improvements to my code below?
...ANSWER
Answered 2019-Sep-18 at 19:42I solved the problem by:
- Creating a thread-safe queue to store the services pending to be resolved
- Using a thread-safe list to store the list of already resolved services
- Using an Atomic Boolean flag to see when the ResolveListener is busy
To make the solution more generic, I built an NdsHelper abstract class. It has 2 functions that must be overridden: onNsdServiceResolved(NsdServiceInfo) and onNsdServiceLost(NsdServiceInfo).
I'm using Timber for logging messages but you can replace them by the standard Log function.
This is the NsdHelper class (Kotlin code):
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install RxBonjour
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page