https://kotlinlang.org logo
#ktor
Title
# ktor
k

Kwabena Berko

10/23/2023, 5:16 AM
Quick
ktor 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.
Copy code
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)
                }
            }
        }
a

Aleksei Tirman [JB]

10/25/2023, 8:26 AM
Can you please file an issue with the listed steps of reproduction?
k

Kwabena Berko

10/25/2023, 12:25 PM
Sure, will do that
3 Views