I want to add a Service to my Android app which runs in the background holding a WebSocket connection (possibly over several hours or even days) and regularly sends some data to a server.
Now there seems to be a bunch of WebSocket libraries for Java, and I'm not sure which one I should use:
TooTallNate/Java-WebSocket Description from GitHub: A barebones WebSocket client and server implementation written in 100% Java. http://java-websocket.org/ -- This one is linked in my first result of googling "android websocket". However, it has quite a few open issues, especially about SSL connections, and it doesn't seem to be actively maintained at the moment.
koush/AndroidAsync Description from GitHub: Asynchronous socket, http (client+server), websocket, and socket.io library for android. Based on nio, not threads. -- Again many open issues, but seems to be activiley maintained/worked on.
Project Tyrus Description from Website: JSR 356: Java API for WebSocket - Reference Implementation -- This is made by Oracle. Not sure if it works in Android.
Jetty WebSocket Client API Info from Website: Jetty also provides a Jetty WebSocket Client Library to write make talking to WebSocket servers easier. -- Again: Not sure if it works in Android.
codebutler/android-websockets Description from GitHub: Bare minimum websockets (hybi13/RFC) client for Android -- This one is used in schwiz/android-websocket-example, which is the accepted answer for the StackOverflow-question "How to make the Android device hold a TCP connection to Internet without wake lock?".
Atmosphere/wasync Description from GitHub: WebSockets with fallback transports client library for Node.js, Android and Java http://async-io.org
TakahikoKawasaki/nv-websocket-client Description from GitHub: High-quality WebSocket client implementation in Java.
square/okhttp Description from GitHub: An HTTP+SPDY client for Android and Java applications. http://square.github.io/okhttp/ --
It has a Websocket module.As mentioned by scorpiodawg, OkHttp has built-in websocket support since version 3.5.firebase/TubeSock Description from GitHub: A WebSocket client library implemented in Java
Autobahn|Android (GitHub) Description from Website: Autobahn|Android is an open-source networking library for Java/Android created by the Autobahn project that implements the WebSocket Protocol and the Web Application Messaging Protocol (WAMP) for creating native mobile WebSocket/WAMP clients. -- cloudsurfin pointed out that this has no support for wss.
In addition, there is a native socket.io client library for Android:
- nkzawa/socket.io-client.java Description from GitHub: Full-featured Socket.IO Client Library for Java, which is compatible with Socket.IO v1.0 and later.
To use the socket.io Android client would be handy for me, because I plan to use nodejs/socket.io for the web frontend anyway. But the native client is quite young and has several open issues. And in addition to that, it is my understanding that an android app does not have any benefit of using the socket.io client library (apart from being compatible with socket.io 1.0 server), because WebSocket support can be assured at the client side.
My requirements are as follows:
- Compatibility with Android API 9 and higher
- Possibility to connect via SSL
- Keep the connection for a long time without having to hold a permanent wakelock
- Compatibility with an available nodejs websocket server implementation or with socket.io
Any suggestions which one is the right library for these requirements?