Kwabena Berko
10/23/2023, 5:16 AMktor tcp
question.
For the below code on a jvm
environment, when the server abruptly closes, we immediately get a null for receiveChannel.readUTF8Line()
, but on iOS
we never get a null and readUTF8Line()
continues to suspend. Is there a workaround to this?
Thanks in advance.
val selectorManager = SelectorManager(Dispatchers.IO)
val socket = aSocket(selectorManager).tcp().connect("127.0.0.1", 9002)
val receiveChannel = socket.openReadChannel()
val sendChannel = socket.openWriteChannel(autoFlush = true)
launch(Dispatchers.IO) {
while (true) {
val greeting = receiveChannel.readUTF8Line()
if (greeting != null) {
println(greeting)
} else {
println("Server closed a connection")
socket.close()
selectorManager.close()
exitProcess(0)
}
}
}
Aleksei Tirman [JB]
10/25/2023, 8:26 AMKwabena Berko
10/25/2023, 12:25 PM