2

I am quite new to Android developpement and Google App engine stuff. I am still into processing the documentation and the tutorials about it.

I have a game concept for Android, based on a turn-by-turn battle for 2 players, but with very short turns (< 20 secs). For what I have understand this far, Google Cloud Endpoints allows to create a REST-like API.

Is there a way for the app to warn a client that the other player has played, and react accordingly ? Because of the "small" timer, one is not expected to leave the app for the during of the battle.

So far, I have found the Channel API, but it is not avaiable for Android clients.

Thank you in advance !

Ashish Awasthi
  • 1,302
  • 11
  • 23
Kamalen
  • 766
  • 6
  • 21
  • Have a look at: http://developer.android.com/google/gcm/index.html – voscausa Jul 22 '14 at 13:32
  • Oh, so it is not restricted only to notifications. I will look further into that one. But if a user has disabled push, to save battery life, it won't work anymore right ? – Kamalen Jul 22 '14 at 13:47
  • Other concern : the 100 ongoing message limit are per device or for the whole application ? If it's the the whole app it will not scale very well. – Kamalen Jul 22 '14 at 14:14

2 Answers2

1

Google Cloud Messaging for Android is meant just for pushing from server to Android client. You will need the Messages with payload and handle it in your Android app.

For high volumes of push messages, you should also consider keeping a dedicated live connection using Socket API

Ashish Awasthi
  • 1,302
  • 11
  • 23
  • Ok so it is the way to do it. I am however still wondering about the 100 message limit : is it per device or for whole API key ? If it is per API key, it seems very small. – Kamalen Jul 24 '14 at 08:17
  • 100 is limit for messages that can be stored in GCM when device is not consuming (offline). that should not be the case when user is playing a multi-player game – Ashish Awasthi Jul 24 '14 at 14:48
  • GCM index page (http://developer.android.com/google/gcm/index.html) first para says, "GCM is completely free no matter how big your messaging needs are, and there are no quotas" – Ashish Awasthi Jul 24 '14 at 14:58
0

Personally, I suggest using the PubNub lib, http://www.pubnub.com/docs/java/android/android-sdk.html, which IHO is more robust than GCM.

When a game is created with x number of players, each player would programmically be subscribe to a pubnub channel.

When player X does something in the game, that action would be instantly published in the channel, and all the players subscribed to that channel would instantly get notification ( in the code) of that action, so then you could take that indication and visible notify the awaiting player its her turn.

Here's a snippet of using the Pubnub id lib on the client side, to receiving incoming msgs on a particular chan:

    public void Startpubnub(String channel) {
Toast.makeText(this, channelName+"TransportLine activated...", Toast.LENGTH_LONG).show();
Log.i("PUBNUB", channelName+"TransportLine activated...");
try {
    pubnub.subscribe(new String[] {channel}, new Callback() {
        public void connectCallback(String channel) {
            notifyUser("CONNECT on channel:" + channel);
        }
        public void disconnectCallback(String channel) {
            notifyUser("DISCONNECT on channel:" + channel);
        }
        public void reconnectCallback(String channel) {
            notifyUser("RECONNECT on channel:" + channel);
        }
        @Override
        public void successCallback(String channel, Object message) {
            Log.i("tag","broadcast is sent!");
            notifyUser(channel + " " + message.toString());
            Log.i("afterBroadcastisSent", message.toString());
            try {
                Message m = Message.obtain();
                Bundle b = new Bundle();
                b.putString("message", message.toString());
                m.setData(b);
                mMessageHandler.sendMessage(m);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        @Override
        public void errorCallback(String channel, Object message) {
            notifyUser(channel + " " + message.toString());
        }
    });
} catch (PubnubException e) {

}

Then subscribe to that chan on your backend aswell, http://www.pubnub.com/docs/java/javase/javase-sdk.html, https://github.com/pubnub/python, then pub a msg back to the chan based on the incoming msg.

You can even communicate with GCM over PubNub.

And if you plan on supporting devices especially international based devices, that doesn't have google play services install because of licensing issues, PubNub is the ultimate quick and fast real time push/pull mechanism. PubNub is essentially that Socket communications that @Ashish described above but outside of Google infrastructure.

sirvon
  • 2,547
  • 1
  • 31
  • 55