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.
-
There's a [similar question](http://stackoverflow.com/questions/19640703/what-is-the-technology-behind-wechat-whatsapp-and-other-messenger-apps) to yours please check it, it should be helpful. – Mahdi Chamseddine Jul 05 '15 at 13:10
-
Why down votes? Google send me to this question and I really found this helpful to me. I know slimier question has already been asked before but the title of this question is more searchable than other one. – Muhammad Saqib Mar 08 '18 at 18:30
3 Answers
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.

- 1,708
- 2
- 15
- 29
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

- 1,111
- 13
- 17
-
The person who posted the question might be aware of problems with TCP for the chat application. WS might be a solution but the answer is not focusing on WS. The node js solution is just an application that does not qualify to be an answer; because the technology used by the application is still unknown and closed source. The response contains 322 words and states there are more big topic exists, on server processing (That is out of the scope of question). – Prashant Mar 11 '23 at 16:51
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

- 3,503
- 3
- 30
- 48