we have already implemented GCM over HTTP for our chat functionality, but after reading GCM XMPP xmpp document and google states below benefits offered by xmpp
Benefits :-
The asynchronous nature of XMPP allows you to send more messages with
fewer resources.
Communication is bidirectional—not only can your server send messages
to the device, but the device can send messages back to your server.
The device can send messages back using the same connection used for
receiving, thereby improving battery life.
we choose HTTP, since we are comfortable in developing using http rather than XMPP. but my concern is, will XMPP provides long term solution for our chat functionality?.
And i am not getting first two points, fewer resources (what exactly it is, when compared to HTTP), secondly, bi-directional messages, i see this can be achieved in HTTP either ,my flow diagram for http flow
i understand in http we need to create new connection when ever we need to invoke backend, so XMPP has advantage here. I would like to know is HTTP is right choice for chat functionality? for longer run..
XMPP should be used over HTTP for continuous communication.
XMPP supports upstream messaging, with HTTP your client (phone) has to make an HTTP call to your app server, you cannot send an upstream message to GCM without XMPP.
XMPP makes fewer connections so overhead (battery, data etc) is much less than with HTTP.
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 am fiddling with Smack on Android and utterly confused as to how to integrate my own database users with this XMPP client. From what I understood, XMPP has its own notion of users and groups with their login credentials. Also, they have helper objects for Chat and ChatManager.
I have my own database of users, and chat messages which I want to store at my server and device. Let us say the user has id - id1. Now:
how do i authenticate the user, i mean what would be the credentials.
how to listen to the incoming messages for the current user.
can i use REST interface to send chat messages to my server and not through XMPP client - in that case would the above listener would still work ?
Using smack - do i still get the control to manage what object i use for Chat message for communication between my server and client.
Basically, I think I am not able to visualize the stuff happening behind the scenes at server (or how to implement it ). Can some one please explain the very basics or point to me in the right direction.
You need to have XMPP server application (ejabberd, prosody, openfire, tigase, etc.) to authenticate users. Most of XMPP servers are able to authenticate users against your own user database/REST API, or you can write simple plugin/script. You can write your own XMPP server too, but it may be too complex task.
Smack documentation provide useful messaging examples
Your REST interface may send XMPP messages too, or you may need to write additional XMPP server plugins to monitor new messages in your database, depends on your service architecture
Your can extend XMPP message as you like, just keep your extended message fields in your own XML namespace. Of course, you may need to extend XMPP library both on client and server to support these new message elements.
We have a requirement forMachine to Machine communication via our servers.
We initially planned to use MQTT+Rabbit MQ adapter to queue up published messages from clients, process the messages in server and publish it back to other set of subscribers.
With GCM supporting upstream messages via XMPP CCS, the same could be achieved through GCM itself, Since its GCM we dont need to worry about maintaining persistent tcp connection with our servers, and it reduces effort both in server and client side.
Now What are all the design aspects and technology limits should be considered in choosing MQTT with GCM?
GCM supports HTTP and XMPP but not MQTT
This article reflects some of the pros/cons on MQTT vs GCM with XMPP
http://ollieparsley.com/2013/05/20/using-mqtt-as-a-gcm-replacement-for-android-push-notifications/
But at the end depending on your specific need you should implement two test clients and see wich one is more efficient on battery usage and message reliability.
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.
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.