Klient2Klient icon indicating copy to clipboard operation
Klient2Klient copied to clipboard

Discovery doesn't work on Android

Open TomTruyen opened this issue 3 years ago • 3 comments

While implementing this library as a way of transfering data between my desktop and android application (written using Kotlin Multiplatform).

The desktop application finds itself and the android application. The android application on the otherhand is only able to find itself and not the desktop application. NOTE: when using an actual android device instead of emulator, the desktop CANT find it...

I don't know exactly how the discovery process works. From what I can tell it uses Broadcasting, but that doesn't explain as to why the desktop application can find the Android application but it doesn't work the other way around...

I'm using all permissions in the AndroidManifest of this stackoverflow article. I also have tried using a MulticastLock which doesn't seem to affect anything

Extra information that might be helpful:

  • The ip of the android device is in the subnet: 192.168.1.x (or 10.2.2.x when using emulator), but both don't work
  • The ip of the desktop is in the subnet: 192.168.0.x
  • The port I'm using: 34340 (but the issue persists with other ports)

My Discovery Builder:

private val discover = Discovery.Builder(CoroutineScope(Dispatchers.IO))
        .setPort(34340)
        .setPing(1000L)
        .setDiscoveryTimeout(60000L)
        .setDiscoveryTimeoutListener {
            println("Discovery timeout")
            scope.cancel() //cancels another scope that is running (has nothing to do with the package directly)
        }
        .setDiscoverableTimeout(60000L)
        .setDiscoverableTimeoutListener {
            println("Discoverable timeout")
        }
        .build()

I don't know if this is an issue with the package directly, or the documentation or just Android in general...

I should state that the main goal is to sync my applications across devices on the same network

TomTruyen avatar Jul 21 '22 13:07 TomTruyen

Can you please provide information how you start discovery on both ends.

Additionally I don't recommend using emulators, especially not mixed with real devices.

And FYI you can't broadcast to different subnets because Routers don't usually forward packets to different subnets.

DatL4g avatar Jul 21 '22 14:07 DatL4g

To get broadcast over multiple subnets to work, we would need a Multicasting service. I've never done that and absolutely no time to look into this, however if you're familiar with it, you can open a corresponding pull request.

DatL4g avatar Jul 21 '22 14:07 DatL4g

fyi, I rewrote this library using ktor, and tried to expand things to ios. project can be found here: https://github.com/fluxxion82/k2k. desktop and android apps seem to work ok for the most part. ios is close to working but having some issues.

fluxxion82 avatar May 05 '23 22:05 fluxxion82