adroitandroid / Near

A P2P library for Android for discovery on local networks using UDP and transfer in general using TCP sockets
https://goo.gl/kioAiQ
MIT License
349 stars 92 forks source link

Can makeDiscoverable by service like NSD? #12

Open hienlt0610 opened 4 years ago

hienlt0610 commented 4 years ago

I have a lot of devices and I want to group them by service, can you do it? ex: makeDiscoverable (String hostName, String serviceName);

makeDiscoverable ("My android device", "printer.tcp");

Look for devices that have the "printer.tcp" service registered instead of searching for them all startDiscovery ("printer.tcp")

DatL4g commented 4 years ago

This doesn't work. But even if it did, everything is searched and then filterd out. (No performance advantage)

And you can build a filter by yourself (e.g. a specific string inside the hostname)

DatL4g commented 4 years ago

When @adroitandroid creates Release v2.0 you can use it like this:

Kotlin

val nearDiscovery = NearDiscovery.Builder()
.setContext(this)
.setDiscoverableTimeoutMillis(DISCOVERABLE_TIMEOUT_MILLIS)
.setDiscoveryTimeoutMillis(DISCOVERY_TIMEOUT_MILLIS)
.setDiscoverablePingIntervalMillis(DISCOVERABLE_PING_INTERVAL_MILLIS)
.setDiscoveryListener(getNearDiscoveryListener(), Looper.getMainLooper())
.setFilter(Regex("printer.tcp")) // shows only devices with parameter "printer.tcp"
.build()

Java

NearDiscovery nearDiscovery = new NearDiscovery.Builder()
.setContext(this)
.setDiscoverableTimeoutMillis(DISCOVERABLE_TIMEOUT_MILLIS)
.setDiscoveryTimeoutMillis(DISCOVERY_TIMEOUT_MILLIS)
.setDiscoverablePingIntervalMillis(DISCOVERABLE_PING_INTERVAL_MILLIS)
.setDiscoveryListener(getNearDiscoveryListener(), Looper.getMainLooper())
.setFilter(Regex("printer.tcp")) // shows only devices with parameter "printer.tcp"
.build()

Setting Parameter

nearDiscovery.makeDiscoverable("hostName", "printer.tcp")

And the issue can be closed then