I don't think my question is original and maybe I already have my answer but I feel a bit lost.
I have an android box (the client) that exists and retrieves information from the server and then displays that information. The client is making a call to the server once ever second to check to see if there is a change in the information. This is ok right now however when we have 500 clients hitting the server once every second this is going to start getting heavy.
QUESTION: Is there a way for the communication to occur the opposite way. I would like the server to tell the client when it has updates rather than client to server.
We are currently using Retrofit by KDubb and the communication is working great but I don't think it will accomplish what we are looking for, or will it? I know you can do Asynchronous communication but I don't know the clients address because it is sitting on a local network somewhere (a home or business) and I don't want the customer to worry about firewall or router issues.
Would Long Polling accomplish what I have described? Is there another technology that would work better than long polling or will retrofit do what I want it to do?
I am using a Spring platform and we are communicating with Android.
So after a lot of testing I have found that GCM (Google Cloud Messaging) to be the best option for my application. It uses XMPP and is pretty fast. Google does not limit you to the number of messages you can send back and forth however you do need Google play services enabled on the android side. I am currently using spring and I needed to use these libraries.
<dependency>
<groupId>org.igniterealtime.smack</groupId>
<artifactId>smack-core</artifactId>
<version>4.0.3</version>
</dependency>
<dependency>
<groupId>org.igniterealtime.smack</groupId>
<artifactId>smack-extensions</artifactId>
<version>4.0.3</version>
</dependency>
<dependency>
<groupId>org.igniterealtime.smack</groupId>
<artifactId>smack-debug</artifactId>
<version>4.0.3</version>
</dependency>
<dependency>
<groupId>org.igniterealtime.smack</groupId>
<artifactId>smack-resolver-javax</artifactId>
<version>4.0.3</version>
</dependency>
<dependency>
<groupId>org.igniterealtime.smack</groupId>
<artifactId>smack-tcp</artifactId>
<version>4.0.3</version>
</dependency>
<dependency>
<groupId>org.igniterealtime.smack</groupId>
<artifactId>smack-jingle</artifactId>
<version>4.0.3</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
This is using Maven, I am sure there are a few others that were already included in my project that are not in this list. After I included these libraries the code snippet that google gives here works with almost no modification.
Long Polling would have worked and so would have sockets. However with number of connection possible we decided having that many connections open was a bad idea, that is why we moved to GCM.
It didn't seem like there were many examples out there for using spring with GCM so here are a few links I had found. https://code.google.com/p/gcm/source/browse/#git%2Fgcm-server%253Fstate%253Dclosed
http://www.grokkingandroid.com/xmpp-server-google-cloud-messaging/ https://github.com/writtmeyer/gcm_server/tree/master/src/com/grokkingandroid/sampleapp/samples/gcm/ccs/server
http://hmkcode.com/android-google-cloud-messaging-tutorial/
A warning. GCM doesn't seem to jive well with spring. XMPP can be installed as a service by itself with sprig however it doesn't use the code that Google helps you with. If you find that this info is wrong, I welcome a different answer.