Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does whatsapp instantly receive a message?

Tags:

java

android

I'm trying to make a communication between my App and the server side. The app needs to receive messages from the server because it's remotely controlled. It works as a Background Service.

I'm currently getting the messages from the external MySQL by using HTTPPost, doing requisitions every 20 seconds, but it spends much battery.

I tried doing a Socket connection to a server (build in java): device connects to the server every 20 seconds and close the conn when it just receive the data, but it also spends much battery.

Is there a way of receiving these messages instantly as Whatsapp does?

like image 494
Israel Agostinho Avatar asked Oct 16 '25 06:10

Israel Agostinho


1 Answers

If the app is open it's most likely a socket connection. This is usually how messengers work.

In the background though it's most probably using push notifications (Check FCM - Firebase Cloud Messaging). This source of info can be unreliable so making a service with requests once a minute or two could be cool

like image 146
Vendetta8247 Avatar answered Oct 17 '25 19:10

Vendetta8247