How to close/retry/manage a WebSocket using Koush AndroidAsync?

a 夏天 提交于 2019-12-01 03:59:57

I read the source code of AndroidAsync.

How to close

WebSocket interface inherits close() method from DataEmitter interface. Calling the close() method closes the WebSocket connection, but note that the implementation (WebSocketImpl.close()) does not perform the closing handshake which is required by RFC 6455.

Also, onDisconnect() in WebSocketImpl closes the underlying socket without performing the closing handshake when it receives a close frame.

So, in any case, the closing handshake is not performed. But, this is not a serious problem if you don't mind error logs on the server side.

How to retry & How to provide notifications

You may be able to detect disconnection by setting callbacks via setClosedCallback() method and setEndCallback() method, but I'm not sure.

How to retry and how to provide notifications are up to you. You can do as you like after you detect disconnection.

Recommendation

If you want to receive fine-grained events that occur on a WebSocket and want to know details about errors, try nv-websocket-client. Its listener interface has many callback entry points and it defines fine-grained error codes. The new WebSocket client library performs the closing handshake correctly.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!