Do I need a database server as an intermediary when using GCM if I don't have data to store?

It looks like this is what is currently needed:

Client 1 -> backend -> GCM -> Client 2.

But I'm not sure what the backend server will do in my scenario where I don't want to store any data. I just want client-to-client interaction through GCM:

Client 1 -> GCM -> Client 2.

Is it possible?

+3


source to share


2 answers


In GCM, the sender (usually the backend) must have an API key that you get from the Developer Console. This API key is used in every HTTP request sent to the GCM server as a form of authorization to send messages.

The client needs to register using the Sender ID that comes from the same project on the Developer Console where you got the API key. This results in a registration token that the client sends to the server / sender. This token is what identifies the client device from other client devices.

The demo app actually has a setting a bit like what you wanted: it acts as both sender and receiver. This only works because we know there will only be one sender and one recipient. The difficulty begins when there are several receivers. The sender will need to keep track of all their registration tokens. You will need to communicate that there is one sender for each new registrar registration token (you need to do this by posting outside of the GCM - usually via a POST call to the server, which cannot really be done on the device). If the sender has to keep track of a thousand tokens, he will have to do it himself.



Note that the above scenario only applies to a single sender-multiple sinks / clients setup. If you need more than one device to be able to send, you will need to allow the other device to track the registration markers of its receivers. This complicates the complexity a bit.

At a minimum, you actually have data to store: device registration tokens that will receive messages from the sender. However, the sender also needs to track responses (for debugging and monitoring purposes). Having said all that, while you could technically use your client device as a server / backend, it runs a lot on the device and is difficult to maintain. I highly recommend setting up at least a very basic server.

Hope this helps!

+1


source


GCM is for sending notifications from the backend to the device and vice versa. https://developers.google.com/cloud-messaging/

Thus, the following options are possible:



Client 1 -> Backend -> GCM -> Client 2. (HTTP)

Client 1 -> GCM -> Backend -> GCM -> Client 2. (XMPP)

+2


source







All Articles