I'm trying to use ktor's raw socket support for do...
# ktor
c
I'm trying to use ktor's raw socket support for doing some udp stuff on my local network. I get a stack trace of
Copy code
E FATAL EXCEPTION: DefaultDispatcher-worker-1
Process: com.test.myapp, PID: 31900
java.net.ConnectException: Permission denied
Yes my android app has internet permission. If I remove the internet permission i get a diff error (
java.net.SocketException: Operation not permitted
) Am I missing something? 2 lines of ktor code in thread
Copy code
val selectorManager = SelectorManager(<http://Dispatchers.IO|Dispatchers.IO>)
  val socket = aSocket(selectorManager).udp().connect(InetSocketAddress("255.255.255.255", 1000))
c
I seem to recall needing this permission when working with webrtc, which also runs over udp https://developer.android.com/reference/android/Manifest.permission#ACCESS_NETWORK_STATE
But it may have been a different problem. Just an idea though
c
Hm good idea
Nope. Same error " java.net.ConnectException: Permission denied"
e
does that work on any platform? I don't think you "connect" to a broadcast address, you simply send datagrams…
c
i have no idea what im doing (first time playing around with udp, but there's this "smart" enabled thing on my network that works over udp 255.255.255.255 on a specific port so I'm trying to talk to it.) let me search for sending datagrams with ktor (TIL of datagrams) edit: the D in UDP stands for datagrams. lol
c
You may need to configure your network security config to allow that traffic https://developer.android.com/privacy-and-security/security-config
e
or try it out on desktop first
c
yeah. tried that but seems to udp on desktop has bugs on macos preveting it's usage according to @Aleksei Tirman [JB] in some past threads here
for my device I'm trying to connect to, it seems like all I want to do is find the device via "udp broadcast". so im not sure if ktor can even do that.
e
looking at the docs you probably want to
Copy code
.udp().bind { broadcast = true }.send(..., InetSocketAddress(...))
and not
connect
, at a minimum. not sure if other changes would be required too
but do you really want to invent your own network peer discovery protocol, we've already got a bunch
even if you don't want to use libraries like google nearby connections, mdns/dns-sd are standard and have platform support https://developer.android.com/develop/connectivity/wifi/use-nsd https://developer.apple.com/documentation/dnssd
c
so funny enough. i used dns-sd in a project like last month so im comfortable with that. but like i said i have a new side project at home due to an IoT thingy of sorts that was installed at my house. now apparently the only way to find it and talk to it over tcp, is to first find it via udp.
.udp().bind { broadcast = true }
that looks promising... I'll give that a shot!
mentally. im also taking note of all of the different ways you can do discovery of devices: seems like 1. dns-sd 2. udp discovery (still unsure how this works honestly) 3. upnp