``` override suspend fun receiveData(): String? = ...
# ktor
o
Copy code
override suspend fun receiveData(): String? = coroutineScope {
        var data: String? = null
        try {
            // 512 here is the MAX size of a IRC message
            val bbToString = { bb: ByteBuffer ->
                try {
                    var decoder = StandardCharsets.US_ASCII.newDecoder()
                    var charBuffer = decoder.decode(bb)
                    data = charBuffer.toString()
                } catch(e: Throwable) {
                    throw e
                }
            }
            input.read{ byteBuffer: ByteBuffer -> bbToString(byteBuffer) }
            if(data == null) {
                throw Exception("BasicConnection.kt: Didn't receive data from connection!")
            }
            println("Data size = ${data?.length}")
        } catch(e: Throwable) {
            e.printStackTrace()
        }
        data
    }
I tried using this function call to receive data from the irc server, but it seems the input is receiving null after sometime... How do I be sure that it is not my net speed(which is very slow) that is causing this drop in connection? Is it the function call's approach instead, for exampleand if so, how can it be improved?
d