<@UL1A5BA2X> Sure. I’m using a unix domain socket ...
# ktor
s
@Big Chungus Sure. I’m using a unix domain socket to communicate between a kotlin native binary and a Compose JVM application, to access the camera feed and send it. I’ve found the release version of a kotlin-native application to be more than fast enough on old, low-end hardware, at least on mac. Code posted in thread.
👍 1
Create a unix domain socket and wait for connection:
Copy code
remove("test")
val tcp = aSocket(SelectorManager()).tcp()
val server = tcp.bind(UnixSocketAddress("test"))
println(server.localAddress)

val serverConnection = server.accept()
val serverOutput = serverConnection.openWriteChannel(autoFlush = true)
In your java client connect to the socket:
Copy code
val tcp = aSocket(SelectorManager()).tcp()
            println("waiting for connection...")
            val clientConnection = tcp.connect(UnixSocketAddress("test"))
            val clientInput = clientConnection.openReadChannel()
Send data from Kotlin native:
Copy code
serverOutput.writeStringUtf8(imageBase64)
                    serverOutput.writeChar('\n')
b
What made you choose this over jni?
s
JNI has been a nightmare for me previously, of memory strange memory issues. We also kill the process at the end so it’s fresh every time too which gives me some confidence that something screwy hasn’t happened with it. Can we even use JNI with Kotlin/native [easily]? I’ve never tried. My native app is accessing objc libs, which has a complicated runtime.
b
I've managed to do it, but can't comment on long term experience. Here's a teaser: https://github.com/mpetuska/fake-kamera/tree/master/jni
s
@Big Chungus So you call a Kotlin native library from JVM?
b
Yes, via jni
And kn binary is embedded in the jar