有没有办法检查与ktor WebSocket lib的Android设备上的连接状态?我想通知当WebSocket连接或断开连接.这有什么乐趣?
这是我的代码:
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")
字符串
}
1条答案
按热度按时间lnxxn5zx1#
您可以查看是否收到了关闭帧:
字符串
或者检查DefaultClientWebSocketSession是否有closeReason:
型