Is it possible to register many diferent servers to notify users with c2dm?
The ting is, my users will host the serverside on there own, meaning one user will always get the messages from the same server but almost all users will have there own server.
Do anyone know if this is possible, or should i start searching for a diferent solution?
This is possible, but I'm not sure you want to do it.
C2DM push uses a Google Account to send messages, so the messages can originate from any server. Your app will receive a registration id and will need to send it to the server that will send it messages. The server will need this id, as well as the Google account information to send a C2DM message to the device.
I'm guessing you probably don't want to do this, so might I recommend a couple of other options:
Have the user's server send the message to your server, which forwards it to the C2DM service and ultimately the device. Your app will send your registration ID to your server.
-or-
Have the server software on your user's server request a Google ClientLogin Token from your server. Your app will have to send the registration ID to your users server. //I don't know if this will actually work, I think it will in theory, but if Google checks IPs or something with the token it might not.
Related
I am trying to make a simple messaging app that has a mysql and php server with an android app. My back end revolves around mysql to store and php to communicate from the database to the device and vise versa.
Now, what I am trying to accomplish is this: sending device->GCM->target device.
What I had in mind was that the database I created stores the gcm Id for all user. That way, when a user wants to send a message, their app sends a message to my database to be stored and retrieves the targets gcm Id and then sends the targets gcm id to the gcm servers to create the push notificiation. When the target receives the gcm message, it sends a response to the database to receive the actual sent message.
Is this possible, and how would I go about doing this?
I already have a gcm receiver implemented from here:
https://github.com/codepath/android_guides/wiki/Google-Cloud-Messaging
No. Don't do it.
For any internet connected device (server or mobile) to request a push to a device, it needs to send a POST request to the GCM address (https://gcm-http.googleapis.com/gcm/send) passing the server API key and the device GCM reg id which should receive the message. And having any of those values available on a device is a security risk for your application.
Having your registration ID, means ppl could easily "copy" your ID and start sending messages from their servers on your behalf.
The GCM device registraion ID, means anyone could start spaming your users, and you certainly don't want that.
You could look into GCM Upstream (https://developers.google.com/cloud-messaging/upstream) but that only means your client code will be easier, as it's as simple as calling gcm.send(String);, but you still have to handle that on your server application.
The correct way is to have on your server a table that maps userId with gcmRegId and have devices send to your server messages to their desired userId. Your server should process one device "send" message and create a push to the other device. That logic should be fairly simple on the server side, after you already have a whole chat application developed.
I'm new to push notifications and here's what I understood so far -
Client app will need to register with Google Cloud Connection Server (GCCS).
GCCS will return a registration ID back to the client.
Client will send the device id and registration ID to the app server.
App server will store device & registration in its database. This database could get huge depending on the number users.
The app server in my case comprises of a single HTML page, and a node.js script. Admin will get to the page, types in a message and hits Send.
The app server will make a POST call to GCCS with the Sender ID, API Token, array of registration ID's etc.
Message is received by the devices.
There is also this thing called as Topics that the client apps can subscribe to. Using Topics, you do not have to send registration ID's of all devices. All devices "subscribed" to this Topic will get the message. This is very useful if you have millions of users (depending on the popularity of the app) and you don't have to split the registration ID's into chunks of 1000s to send the message.
My questions are -
If we're using Topics, do we need to persist the Registration ID, Device ID to a database on the App server? It seems redundant.
Are there any ready-to-use/commercial GCM servers that can send Topic messages?
Is it easy enough to build on your own (since its a simple POST call)? If I'm going to use JavaScript, wouldn't I run into CORS issue?
Thanks for the help!
If we're using Topics, do we need to persist the Registration ID, Device ID to a database on the App server? It seems redundant.
Are you referring to C2DM implementations? Those are deprecated as shown on the GCM documentation. In relation to topics, they may not be necessary but are necessary to other message calls.
Based on the documentation, to needs to be set as topic/[yourTopic] with the necessary payload
https://gcm-http.googleapis.com/gcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
{
"to": "/topics/foo-bar",
"data": {
"message": "This is a GCM Topic Message!",
}
}
Are there any ready-to-use/commercial GCM servers that can send Topic messages?
I can't find any sources about this, so I'm guessing we're left to implement it on our own application server. Google provided us with a sandbox project for us to play with.
Is it easy enough to build on your own (since its a simple POST call)? If I'm going to use JavaScript, wouldn't I run into CORS issue?
If you're talking about setting up the Client App (specifically Android), there's a setup guide on the documentation. But if its more on the application server, I can't comment on it really. XMPP libraries can be used to handle XMPP Connection Servers
I'm looking to create for my app some authentication. This will basically consist of a user registering (preferably with their google account, although not necessary) and providing a username that is then sent to my server and then having the ability to log in. I then from there would like to be able for the client app to communicate with my server by sending data and receiving push notifications via GCM (google cloud messaging). It is important that the server is able to send a push notification directly to a certain user not to all registered devices.
Would someone be able to point me in the right direction for what I must do? I've had a look at a few tutorials but what I've seen has always sent messages to all registered devices not to a specific user.
Some extra information about the app:
-The client app (user) will need to send a piece of information to the server. This information will also include the user that it needs to be sent to. Once the server receives the piece of information it should send a push notification through GCM to the specified user's client app.
I'm clueless as to how I need to go about setting up the authentication system, any help would be very appreciated!
Thank you very much,
Daniel
Offcourse you can send push notifications to selected users. This process would roughly comprise the following steps:
1) send the User's GCM registration id to your own server along with a unique user id (what ever id you have assigned to that user; could be email or sim id or something like that). Save it in your database.
2) To send Push notifications to selected users, choose users from the database based on some criteria, retrieve their GCM registration ids from the database and forward them the GCM server.
but there is one important thing you must handle. GCM registration ids could change e.g if user uninstalls and re-installs the application. You must update you corresponding database entry in that case.
I am trying to write an application which notifies a cellphone using GCM. I was able to implement basic functionality, but there is one question I'm still unsure of
As I understand, the flow goes like this:
Device start up
Device registers, obtains registration id
Server gets the knowledge of registration id on device
Server is using it's API key + registration id to send payload to device
Device receives payload.
One thing which is unclear to me is: what is a proper methodology to implement step #3?
I could not find any way to obtain a list of registered devices. Lets imagine, I am using GCM for a purpose of posting to a known device, and I could email that ID to myself and then register it on the server manually. But as I understand, it expires.
So, it there an expectation that I have to keep re-registering and somehow notifying server every time it happens?
Yes, your app on device must send registration ID to your server application in order for server to be able to send GCM messages. See third point in Enabling GCM.
For sending the same message to 100 devices via c2dm,
We need to do the following things,
1. get registration of each device that you need to send messages.
2. initiate 100 request one for each device and send it to c2dm.
Am i correct?
Do we really need to send 100 request one for each device. one request containing registration id of each device?
Is there any way that i can send all the device's registration ids in a single request with the message? so that with that request, c2dm will broadcast or push that common message to all 100 devices with that registration ids that it obtained in a single request?
C2dm does not allow batch sending until now. So you still have to send them for each device.
c2dm doesnt allow batch sending. even for my application i have been sending messages with different ids, by storing the ids in a database and retrieving them in a loop. i dont think there is any better solution.