Question

I am creating an android application to get information from a server as fast as possible. I am not interested in security or preserving battery life. The messages will most likely be small but will come in fast (every few seconds). Communication will primarily be uni directional however the ability for the application to communicate with the server would be an added bonus.

I have been looking at Google Cloud Messaging (GCM) however there are mixed reports regarding the speed of this.

How does this compare in terms of speed to say a HTTP/JSON connection? or setting up a socket that the server would connect and push the message to?

Are there any other alternatives I have not considered?

EDIT: This will running exclusively over WiFi

Was it helpful?

Solution

Socket io it provides constant connection with server so it is pretty fast (no time loose on connecting each time).

OTHER TIPS

You can achieve this by using a concept called Long Polling

A typical implementation is as follows:

    @Override
    protected String doInBackground(String... arg0) {
     String result= TIME_OUT;   //public static final String TIME_OUT = time_out_error" 
     while(result.equals(TIME_OUT))
         result = getServerInformation();

     return result;
    }




public String  getServerInformation(){
         String result = null;
        DefaultHttpClient def = new DefaultHttpClient();
        HttpParams httpParams = def.getParams();
        HttpConnectionParams.setConnectionTimeout(httpParams, CONNECTION_TIMEOUT);

        ConnManagerParams.setTimeout(httpParams, CONNECTION_TIMEOUT);
        HttpPost httpPost = new HttpPost(mPushURL);
        httpPost.addHeader("Accept", "application/json");

        try {
            Log.i(TAG, "Executing POST(PUSH) request " + httpPost.getRequestLine());

            HttpResponse httpResponse = def.execute(httpPost);
            Log.i(TAG, result);
            Log.i(TAG, String.valueOf(httpResponse.getProtocolVersion()));
            Log.i(TAG, String.valueOf(httpResponse.getEntity().getContent())); //For testing purposes


        } catch (ClientProtocolException e) {
                 e.printStackTrace();
       } catch (IOException e) {
            e.printStackTrace();
        }
//HERE YOU SHOULD TURN result = TIME_OUT or whatever you want
        return result;

  }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top