小编Key*_*uzi的帖子

有没有办法使用 ktor WebSocket lib 检查 Android 设备上的连接状态?

有没有办法使用 ktor WebSocket lib 检查 Android 设备上的连接状态?我想在 WebSocet 连接或断开连接时发出通知。这有什么好玩的吗?

这是我的代码:

    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")
Run Code Online (Sandbox Code Playgroud)

}

sockets android websocket kotlin ktor

5
推荐指数
1
解决办法
292
查看次数

标签 统计

android ×1

kotlin ×1

ktor ×1

sockets ×1

websocket ×1