Heya! First time working w coroutines and ktor in ...
# getting-started
c
Heya! First time working w coroutines and ktor in Android and everything's gone pretty smooth minus the fact that my loop seems to exits after the first received message. I was under the impression that the coroutine is suspended till another message is registered so I figured I might've messed something up when calling it:
Copy code
suspend fun handle(cameraFragment: CameraFragment) {
        <http://client.ws|client.ws>(
            method = HttpMethod.Get,
            host = httpUrl,
            port = httpPort,
            path = "/exchange"
        ) {
            for (message in incoming)
                if (message is Frame.Text) {
                    Log.d(TAG, "Received msg: ${message.readText()}")
                    when (message.readText()) {
                        "!request_url" -> {
                            send(cameraFragment.rtspUrl())
                        }
                        "!request_img" -> {
                            val byteArray: ByteArray? = cameraFragment.captureImageAsByteArray()
                            if (byteArray != null)
                                send(Frame.Binary(true, byteArray))
                        }
                    }
                }
        }
    }
called using
Copy code
CoroutineScope(<http://Dispatchers.IO|Dispatchers.IO>).launch {
                SimpleAsyncClient(
                    args.ownerAddress,
                    args.ownerPort,
                    this@CameraFragment
                ).handle(this@CameraFragment)
            }
Edit: Issue's caused by the calls to send, fixed it now