I'm seeing some weird issues I'm hoping the channe...
# ktor
s
I'm seeing some weird issues I'm hoping the channel can help me with. Not sure it's ktor or something. I have this library (https://github.com/fluxxion82/k2k) that uses ktor to handle creating sockets and packet transfering. There's some example apps included in the repo, which seem to work pretty well. The issue is when I'm using this library in other apps. The sample apps in the repo include a desktop and android app, and I have another desktop/android app pair using the library. The first issue is that non sample Android app doesn't see either desktop app when trying to discover other clients. If I launch and start the sample android app (on same device), the other android app will start to see the desktop apps. I'm using the library pretty much exactly the same from what I see. The next issue with that after getting the non sample Android app to discover the desktop app, when it tries to send data, it's not received on the desktop app. At some point I was able to send data from the non sample Android app to the desktop app but lately it hasn't been working. I will also add the I think the Android app discover worked the first time I tried it. I'm trying to figure out what the issues could be. if I change the port used for the discovery, then the sample app will not help the other app to start seeing other apps. Same library is being used so socket configurations are the same, library usage is the same, android app permissions are the same. Anyone have any ideas on what the issue could be or things to investigate?
a
Can you explain how the discovering works?
s
There's a DiscoveryServer and a DiscoveryClient. The server part creates a udp socket on address "0.0.0.0", the opens a read channel, and then observes incoming packets. The client also creates a udp socket, then connects to an address, opens a write channel and writes some data before closing, and does this on a loop on all the broadcast addresses the NetworkInterface returns. both sockets have
broadcast = true
when connecting. I was working on things the other day and my main app started working randomly. It goes back and forth with working but it's really weird when one app doesn't work and i start the discovery on the second app, the first app will start to see the other broadcasts. I was thinking maybe it had something to do with the coroutine dispatcher i was using but not sure that's actually the case.
my next issue is sending data on a tcp socket. I have the same kind of thing where i have a client and server setup, creating tcp sockets and trying to send data. It works sometimes and other times it doesn't. these sockets seem very unreliable and not sure what I can do to make them more consistent.
a
It would be great if you could share a code snippet (where Ktor sockets are used directly) to show the inconsistent behavior.