Is there any way to check connectionState on android device with ktor WebSocket lib?

Viewed 177

Is there any way to check connection state on android device with ktor WebSocket lib? I want to notify when WebSocet Connected or Disconnected. Is there any fun with this?

this is my code :

    try {

        client = HttpClient() {
            install(WebSockets) {
            }
        }
        client.ws(
            method = HttpMethod.Get,
            host = "hostName", path = "/ws"
        ) {

            send(Frame.Text("SampleText"))



                for (frame in incoming) {
                    when (frame) {
                       checkFrame()
                    }

                }
            }


    } catch (e: Exception) {
        Log.i(TAG, "${e.message} Exception")

}

0 Answers
Related