Java – How does WhatsApp receive messages immediately?

How does WhatsApp receive messages immediately?… here is a solution to the problem.

How does WhatsApp receive messages immediately?

I’m trying to communicate between my application and the server side. The application needs to receive messages from the server because it is remotely controlled. It works as a background service.

I’m currently using HTTPPost to get messages from external MySQL, making requests every 20 seconds, but it’s draining a lot of battery.

I tried to establish a socket connection to the server (built in Java): the device connects to the server every 20 seconds and closes the connection when it just receives data, but it also consumes a lot of battery.

Is there a way to receive these messages instantly like Whatsapp?

Solution

If the application is open, it is most likely a socket connection. This is how Messenger works.

Although it is likely to use push notifications in the background (check FCM – Firebase Cloud Messaging). This source of information can be unreliable, so it might be cool to provide request service every two minutes

Related Problems and Solutions