1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| webSocketUtils = WebSocketUtils(url,object : WebSocketListener() { override fun onOpen(webSocket: WebSocket, response: Response) { super.onOpen(webSocket, response) Log.d(TAG, "onOpen") } override fun onMessage(webSocket: WebSocket, text: String) { super.onMessage(webSocket, text) Log.d(TAG, "onMessage-->text:$text") }
override fun onMessage(webSocket: WebSocket, bytes: ByteString) { super.onMessage(webSocket, bytes) Log.d(TAG, "onMessage-->bytes:$bytes") }
override fun onClosed(webSocket: WebSocket, code: Int, reason: String) { super.onClosed(webSocket, code, reason) Log.d(TAG, "onClosed-->code:$code\treason$reason") webSocketUtils.endHeart() }
override fun onClosing(webSocket: WebSocket, code: Int, reason: String) { super.onClosing(webSocket, code, reason) Log.d(TAG, "onClosing-->code:$code\treason$reason") webSocketUtils.endHeart() }
override fun onFailure(webSocket: WebSocket, t: Throwable, response: Response?) { super.onFailure(webSocket, t, response) Log.d(TAG, "onFailure-->throwable:$t") webSocketUtils.endHeart() } })
webSocketUtils.startHeart("心跳消息", 1000)
|