Skip to content Skip to sidebar Skip to footer

How To Close/retry/manage A Websocket Using Koush Androidasync?

I'm using Koush's AndroidAsync for a WebSocket client. My code follows the example at https://github.com/koush/AndroidAsync and works. (Example copied below.) I need my app to op

Solution 1:

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.

Post a Comment for "How To Close/retry/manage A Websocket Using Koush Androidasync?"