https://kotlinlang.org logo
Title
t

Tom Carton

04/29/2020, 9:44 AM
Hey! I'm quite stuck on a custom project I'm working on and I'm pretty sure I could greatly learn and improve it with your insights! I'm trying to develop a custom
Chat Mobile Application
as such: - a server in
Kotlin
- clients using
KotlinMultiplatform/Kotlin-native
I want to use sockets to exchange encrypted messages (using a simple xor for instance) in the common/shared part using Posix. Each client displays all the messages and can send new message to the server. The server serves all the clients with any message it received. Nothing fancy on that side... And the main thing I am trying to demonstrate with all this, is how I could share the maximum of code between platforms using
Kotlin-native
and have clients code only responsible for the UI. Period. So I tried to use
Coroutines
to have a background thread listening to incoming messages. These messages could come from socket (in order to be dispatched to the UI) or from UI (in order to be dispatched to socket). But sounds like it doesn't work like this as my application often get stuck or the coroutines stop running. I tried to use a heartbeat to wakeup the coroutines or some time-out to prevent getting stuck but this is clearly black magic and doesn't succeed anyway. Do you have any idea or insight to point out on what I should rather do? or on what I am doing wrong? Thank you!
c

crummy

04/29/2020, 10:12 AM
hard to know without seeing code. can you build a tiny repro?
t

Tom Carton

04/29/2020, 12:45 PM
I'm on my way preparing something to illustrate it... but was mainly curious about how other dev would handle this, a Chat App in a multi platform flavor with as much shared code as possible...
s

Sam Garfinkel

04/29/2020, 1:15 PM
Coroutines in native currently only support single threaded execution
t

Tom Carton

04/29/2020, 1:17 PM
Thank you!
t

Tom Carton

04/29/2020, 1:23 PM
yes, makes sense...
it is single threaded execution on main thread then... I can see that in darwin implementation ;'(
s

Sam Garfinkel

04/29/2020, 8:25 PM
Sadly, yes.