-
Notifications
You must be signed in to change notification settings - Fork 0
websocket
StormKid edited this page Sep 4, 2019
·
3 revisions
OkWebsocket.instance.Config().setTimeOut(15000L).showLog(true)
说明:此两项为了开发的合理性,必须初始化两个方法,不然主动会抛异常。
private val url = "ws://xxxxx"
OkWebsocket.instance.Builder().setUrl(url).build().startSocket(object :
WebsocketCallbackRule<String> {
override suspend fun onMessageSuccess(massage: String) {
click.text = massage
}
override suspend fun onSocketDrop(err: String) {
}
override suspend fun onClosed() {
}
})
// 这里已经自行处理成json对象传递给后端,此处可以发任意信息
OkWebsocket.instance.sendMsg(any)
// ---------------------------------------------
// 例如:
OkWebsocket.instance.sendMsg(hashMapOf("event" to "message"))