I'm creating an application that has to realtime be live with the server. I'm not sure whether to have an always live (or checking with server every 2mins) app because it might drain the battery. What are my alternatives?
WhatsApp uses XMPP (eXtensible Messaging and Presence Protocol) to handle the message delivery system.
XMPP is mostly like HTTP where the client opens the socket with the XMPP server and keeps it open as long as the client is logged in. It's not like the regular REST API where the client opens the socket send/receive the data and close the socket. The socket is opened as long as you are signed in. In case of WhatsApp that's eternity (not really, WhatsApp reconnects automatically if the connection terminates)
As written, use push notifications (working even with closed app) or socket connection (working with app on the background). If the app is on foreground, you can use whatever you want - screen will take most of the battery...
Whats app using XMPP server, as like mentioned in above answer. For free of cost, If you want to create a messenger application like whats app. Tou can use some of the free real-time databases are available in the market like "FireBase" server.
You can get sample code here: https://codelabs.developers.google.com/codelabs/firebase-android/#0
and further information regarding the firebase server and required libraries you can find here: https://firebase.google.com/docs/database/
Related
I'm some kind of backend developer and don't know how mobile applications work. But I need to provide architecture for mobile chat application server.
I know that android apps using google services to receive push notifications from firebase, so we don't need run own application in endless loop and poll for new data at server.
That is prefect for push notifications, but firebase notification body limited by 4KB and don't fit for big messages.
So I can see only one realization:
Google services polling for FCM (ex-GCM) notifications
Receive some signal-like notification
According this notification my app go to server and download new message
Update local chat data
Show generated locally notification for new message
This way is looking pretty complicated, so I don't believe that this is only possible (and correct) way.
Another way is to keep websocket session opened every time or poll server manually. But these two operations should drain battery to much.
So how modern chat apps stay in sync even if they closed and device screen off?
if you really want to make modern chat app then do some research on XMPP
These can be some best practices you can follow
setup XMPP server on backend with offline storage support
use client XMPP SDKS for apps to connect XMPP server.
use push notification in case of server connection lost to wake app
and reconnect to XMPP
try to save large files on different server and send only url with
body if you want to keep your files urls private then use any
client SDK that support implementation of uploading and downloading
private file like AWSS3
Can anyone please tell me how whatsapp messages are received on my mobile? Like, does my phone requests whatsapp serve every second or does the server send my phone a ping when a message for me is received at the server end. I don't want to know the exact procedure, but an overview will do the job.
Well i guess, its just not that easy to answer in this scope however here is how it might work.
For this you may need understanding of technology on mobile side and server side.So let me try to explain it in a very simple manner which may be the implementation.
1) No, your mobile does not ping the server everytime. Polling like this adds lots of overhead on the network, also multiple calls can be stacked up if there is delay in responding thus leading to huge traffic on server side. Instead , its other way round. Whenever the server recieves any msg it pings you instead to say that you recieved a msg.
2) Hope point 1 makes it clear that its other way around. Now would like you to know about push notification. Push notification is something by whichserver can notify mobile of any new msgs or information or update.Here's a link which can give more detail on push notification for android https://parse.com/tutorials/android-push-notifications
3)How the server processes the request. This itself is a big topic. Basically it goes like this.I assume there are two users, A and B
First Mr A send a msg to Mr B
Server recieves this request with information of the user A(i.e the person who sent the msg) and user B(i.e the person to whom the sg is to be sent)
The server does some processing to get to know the user id of Mr B and other infomation about Mr B and then does a push so that user B can recieve this notification.
Of course a lot of technology is involved to do this job in order to handle millions of concurrent connections and responding fast without blocking other connections.
If you want to have a basic view of the technology, i would suggest you to look at socket io and node js. Heres a chat example
http://socket.io/get-started/chat/
Hope this helps
WhatsApp uses XMPP (eXtensible Messaging and Presence Protocol) to handle the message delivery system.
XMPP is mostly like HTTP where the client opens the socket with the XMPP server and keeps it open as long as the client is logged in. It's not like the regular REST API where the client opens the socket send/receive the data and close the socket. The socket is opened as long as you are signed in. In case of WhatsApp that's eternity (not really, WhatsApp reconnects automatically if the connection terminates)
XMPP protocol has been used in various chat applications such as Google Talk, Facebook messenger etc.
As far as actual technology goes, WhatsApp uses heavily customized version of Smack library on Android to build their client and uses customized eJabberd Server to handle the XMPP traffic. They might have different backend solution for handling the data though which might be on one of the cloud storage/computing network (I think it's heroku, no real idea though).
On iOS and other platforms, I suppose they might have developed their own libraries. Developing own libraries is not a lot of work, especially when you have customized needs and have a team of developers. I have used one of the libraries available for Windows Phone and heavily customized them to work for us. I made some improvement on the library, but due to time shortage I couldn't submit them to the original repo (Documentation is really tough).
Anyways, if you are interested in learning the tech, you can read Oriely's "XMPP: The Definitive Guide" and can visit The XMPP Standards Foundation.
Basically to say that when there is a message, Server will sends a notification to Client via Push Service. In before Client must register to use Service with Server, Server will provide an Id for Client and then uses it to specific which Client will receive the message.
Read more in Here and Here
I was developing an android app and a server that serve this apps. The server was coded in cakePHP. I want the app to have a notification from the server when there is an update on whatever things. Is this notification function a Server to client connection ? For example the facebook , whatapps and other social app in smart phone that could receive notification when someone send you a message, tagged you etc.
What is the proper way of doing this? I just need an idea to start. I see someone suggesting to open a long establish connection from client to check whether there is an update, but this would drain the phone battery.
If it's a Server to client connection, how would the server know where to find the client?
Google cloud messaging would seem to be the best option here; https://developer.android.com/google/gcm/index.html
As it says on the tin; "Google Cloud Messaging for Android (GCM) is a service that allows you to send data from your server to your users' Android-powered device, and also to receive messages from devices on the same connection"
xtify seems to also support what you are asking but I've no experience with it.
Although depending on your particular requirements there are other options available.
If the client only needs to get notifications when active you could have it check the server every X number of seconds for updates when it is not asleep or even when the user does a particular action. Of course this all depends on what you want to happen.
edit: Heres a good article/tutorial with code samples https://blog.serverdensity.com/android-push-notifications-tutorial/
I really tried to find a solution to this problem but didn't. There are some threads related to this concept, but I didn't find a comprehensive solution.
I have a server with Openfire which sends messages. When both users are online, there is no problem. However, when a user is offline I would like to send a push notification, as in Whatsapp. I heard that Whatsapp and other IM apps use a modified version of ejabber to send push notifications, but couldn't find out how.
One possibility is to use GCM, but I am not sure if this is the right way to go. Also I would like to avoid polling, for the sake of not draining battery life.
Does anyone know some solution to this or has an example?
I am studying the openfire and found some good options that I would like to share with you.
I found a plugin in github and i will test it this week. It seems that will be a good solution to your goal and to my: https://github.com/meisterfuu/Openfire-GCM/
Another option is to use CallbackOnOffline Plugin that calls a specified URL with To and From parameters. This url could be a endpoint in your web service, and with that data (To and From) you could get the associated Id for push in your base, and did a push.
https://www.igniterealtime.org/projects/openfire/plugins.jsp
Well, you could use GCM with XMPP.
The new GCM Cloud Connection Server allows you to use the XMPP protocol for a bidirectional (Cloud to Device and Device to Cloud) communication between your server and your Android application.
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.
In openfire its done automatically, messages will be recieved by the user when the user gets online. So no worries send message to an offline user and when the user comes online message will automatically pushed to the user.
I'm building an android app where the server needs to know if the user is still online or not.
You can compare it with facebook chat on android. If the user is on the app, other users can see he is online. But when the user loses internet connection or closes the app the server needs to know he is not online anymore.
What is the best way to do this?
It depends on your server type. For example if you use sip you can do this by sending registration message before expire time.
But in general the common practice is to send a keep_alive message within a short interval. if you use any third party standard server then read their documentation and apply that way. If you are planning to create your own server system then just create a custom keep_alive message format and send it to server at regular interval.
#Jeeten Parmar
An easy way to implement a keep_alive system is by using MQTT.
MQTT is a machine-to-machine internet protocol.
http://www.eclipse.org/paho/
When you implement Paho in an Android project, you can subscribe to an MQTT server.
When the client disconnects from the internet, an event can be called. You can even set a lastwill message.
You can also set the keep alive interval. ->
http://public.dhe.ibm.com/software/dw/webservices/ws-mqtt/mqtt-v3r1.html#keep-alive-timer