sfdcdev
sfdcdev

Reputation: 199

Google Cloud Messaging - SERVER SIDE

I need a little help understanding couple of things about gcm - server side. I am working on instant messaging app with the example of server-side here http://developer.android.com/google/gcm/ccs.html

After I execute this code It connects but terminates after few seconds. I can guess that the reason it's because of the main() function.

    public static void main(String[] args) throws Exception {
    final long senderId = 1234567890L; // your GCM sender id
    final String password = "Your API key";

    SmackCcsClient ccsClient = new SmackCcsClient();

    ccsClient.connect(senderId, password);

    // Send a sample hello downstream message to a device.
    String toRegId = "RegistrationIdOfTheTargetDevice";
    String messageId = ccsClient.nextMessageId();
    Map<String, String> payload = new HashMap<String, String>();
    payload.put("Hello", "World");
    payload.put("CCS", "Dummy Message");
    payload.put("EmbeddedMessageId", messageId);
    String collapseKey = "sample";
    Long timeToLive = 10000L;
    String message = createJsonMessage(toRegId, messageId, payload,
            collapseKey, timeToLive, true);

    ccsClient.sendDownstreamMessage(message);
}
  1. Isn't supposed to be a 'while' statement which keeps the XMPP connection alive between the app-server to GCM server?

  2. Isn't The purpose of the server-side in this case (instant messaging app) is to keep the connection alive with GCM server and to listen for incoming messages from clients. messages like: 2.1 When client want to register to the app so I need to store it's details in a database. 2.2 When client want to send message to another client so the server-side app is in charge to forward the message to it's destination?

I have looked for couple of examples for implementing gcm server side using xmpp and all of them were with this kind of main function I mentioned above... Am I getting something wrong?

Upvotes: 1

Views: 549

Answers (1)

Eran
Eran

Reputation: 393801

Yes, the XMPP connection must stay alive. Otherwise, your server won't be able to receive upstream (device to cloud) messages.

I can't say why all the examples you saw don't maintain an open connection. I guess they are simplified examples.

Upvotes: 0

Related Questions