I am trying to create a chat application. The communication is based on RESTful web services(Jersey). The client communicates with the server sending HTTP requests. My problem is how to send messages from server to client without the client send a request first. I read about C2DM notifications, I suppose using this way, when the client receives the notification from the server then (the client) has to send a request to the server in order to receive the data. I also was thinking about using sockets but I don't know if it is possible as I am using Rest. I mean in the server side can I also use sockets(sockets run in lower level) with the REST code? The only thing I have though that could work using sockets is to create another server with socket(two servers RESTful and socket), but is this a good solution? Also could I put some server code in the client side and some client code in the server side. Would it be correct and effective? What do you think? Which solution would be the best?
C2DM has been officially deprecated as of June 26, 2012 by google. Existing C2DM developers are encouraged to migrate to the new version of C2DM, called Google Cloud Messaging for Android (GCM).
Check out this link for more info
http://developer.android.com/guide/google/gcm/index.html
The scenario you describe sounds ideal for C2DM. If you build your own sockets set up you will drain battery and CPU resources doing something the phone is already doing - maintaining an open socket to receive messages.
C2DM is relatively straightforward to set up, and in my experience is pretty reliable.
This is the best tutorial I have seen on it:
http://www.vogella.de/articles/AndroidCloudToDeviceMessaging/article.html
But you also need to read the official docs:
http://code.google.com/android/c2dm/
Your server-side code will need to send an HTTP request to the C2DM servers to send a message to a device. To tell it where to send the message, your server needs to specify the Registration ID (which represents your app running on one specific device) and so when your app sets up on the Android device, it registers with C2DM, and then needs to send its C2DM Registration ID to your server to be stored, ready to be used to send messages to.
Related
Do XMPP Servers such as Openfire require implementation of their own in order to handle messages. Do I need a web language such as PHP in order to handle messages with Openfire?
Because according to posts such as this How to make Chat Application in Android Using XMPP and GCM, I do not need to write PHP scripts in order to handle messages, Openfire (it being a XMPP server) will do all the heavy lifting. So when creating a messaging program is the only thing I need to worry about the client side code?
I've also run into contradictory information that I hope someone can clarify on. It was to my knowledge that one needed to use a XMPP server along side GCM; as GCM is not reliable in delivering messages by itself and requires an XMPP server to fully be reliable. Is this true, the above link suggests that it isn't, but according to this it is https://www.youtube.com/watch?v=5wXGcu9H91s
Some clarification would be great, thanks.
GCM allows you to use both HTTP and XMPP to send messages down from your application server through GCM to your devices.
Only with XMPP though can you send messages from your device through GCM to your server. This allows your device to send acknowledgment messages back up to your server. This does not necessarily make GCM more reliable but it does allow you to have a better audit of what messages were actually received by devices.
Openfire is a server that supports XMPP so you will still have to implement the protocol maybe using Smack.
Note that you could skip GCM and have a connection directly between your app and your XMPP server, however this is not recommended since your app would have to be constantly connected to your server which would be very hard on the battery of the device. This is where GCM comes in, allowing your app to receive messages even when it is in the background but still being kind to the battery of the device.
I need to implement a group chat server which can support more than 50 users at a time.
The users will be only on mobile clients which include Android/Windows Phone.
Sending push notifs to the apps will not be difficult, as the server needs to do a basic curl request. So "polling" is not an issue.
My current skill set includes.
Flask
Google App Engine( I intent to use it or a web hosting
server.)
Basic php
So from what I know, I can make http requests to the server with user specific information+chat msg.
The server processes this and sends a broadcast using push notifs to all the devices stored in database.The server identifies the device from the data in the http request.
How efficient will this be?
If this is not the correct approach, what all do I need learn(sockets programming?) and any framework which can make my work easier (it will help if it is also supported on GAE).
I think you need XMPP messaging. It's support by App Engine but not in PHP : https://developers.google.com/appengine/features/
XMPP permit to send and receive chat messages.
I am creating a chat application on android using GCM. I'm already able do receive messages from the cloud and to send them manually through a PHP script using cURL. I can simple make an HTTPRequest to this script everytime a user send a message but I would like to know if there's a way to remove this script thus making the android app directly send the message to the cloud. If this is possible I also would like to know if it is the "right" way to do it or if the HTTPRequest is as good as it.
Thanks in advance.
Not really. GCM is not meant to replace your entire infrastructure, just the push channel from your servers to the clients.
That said, there is this concept of Upstream Messaging (from device to Google's servers) but Google's servers then contact your servers (via XMPP of all things) to let you decide what to do next.
You cannot do device-to-device over GCM.
I propose a new question:
I think the communication between android and server by sockets is difficult
I speak with my friends it proposes me a solution: use the GCM
month then give an idea or example uses this concept
I found this book:
http://www.academia.edu/2200380/SENDING_SECURE_DATA_BETWEEN_AN_ANDROID_MOBILE_APPLICATION_AND_A_NETWORK_GROUND_STATION
And the question is, how to use gcm between server and Android?
Communication between android and server is I believe not applicable with GCM, GCM is intended to be a server to client pushing service, for example your wish to tell your client there is some data updates you need to fetch. So your server will push a message to client, using GCM.
For client to server communication, the easiest IMO would be using some Http server or web services. As for securing you can always go for SSL.
stackoverflow fellows,
Since I am very new in Cloud Computing matters, I would like to ask you a question: Google Cloud Messaging for Android works from server to client, but also viceversa(from client to server)?
I am asking you this, because I am currently developing an Android application. The structure, in general lines, it's something like: I would like to use my laptop as a server - and perform all the computations here. Then, from my server (laptop), to send everything in the cloud, and from the cloud, directly to my Android running device. I want to perform the computing and database storage on my local server (because, since I am a student, I won't have enough money to actually pay for a server from google (let's say), so I am focusing on what's free and suitable to my needs) and just communicate with my Android device using Google Cloud Messaging for Android. (I want my application to be independent from the hardware of my mobile device, and also, I want to write the program that will perform the computations on my server in Java).
I know that I can send messages from the server to my device(through cloud), but the question is: can I also send messages from my device to the server ? I am asking this, because the computations will be made after I submit something from my device (basically, my Android application will be an interface, from where I can send the data to my server (through cloud) and then receive (also through cloud) the results of the computation on my device)
According to what I've been currently reading (http://developer.android.com/google/gcm/index.html) it seems that I can only send messages from the server to my device, but I decided to ask, since, so far, was the only free messaging framework(using cloud) I have found.
Thank you.
You can use GCM Cloud Connection Server to send messages from device to server.
Paragraph from this page:
http://developer.android.com/google/gcm/ccs.html
The GCM Cloud Connection Server (CCS) allows third party servers to communicate with Android devices by establishing a persistent TCP connection with Google servers using the XMPP protocol. This communication is asynchronous and bidirectional.
Google Cloud Messaging for Android works from server to client, but
also viceversa(from client to server)?
Sorry but GCM(Google Cloud Messaging) is only made up for sending Push Notification from server to device. Not for Viceversa.
I know that I can send messages from the server to my device(through
cloud), but the question is: can I also send messages from my device
to the server ?
For sending the message or anything(For Example: Photo,files..) to Server why Don't you Use Web services for it. I think it will Be suitable according to your Needs.
It is correct what KashifB wrote:
You can use GCM Cloud Connection Server to send messages from device
to server.
But keep in mind that Messages with Payload have a size limit of 4kb per message.