Home > database >  How does whatsapp (or any other massanger) send massages?
How does whatsapp (or any other massanger) send massages?

Time:10-02

I know how to send data to server, how to get data from server, but I don't understand how client knows when to send a request to server, to get the massage. I know that it doesn't ping it every second, but now I don't see any other way.

I will use React JS for the UI with node JS for the server part.

Thanks in advance. <3

CodePudding user response:

Imagine you have:

  • A central server
  • client1 (clt1) that sends the message
  • client2 (clt2) that receives the message

When only clt1 is online and it sends a message:

    1. Store the message of clt1 in the server.
    1. When clt2 reconnects, it sends a request to the server to get the messages.

When both are online:

    1. clt1 sends a message to the server.
    1. As the server knows that clt2 is online, it immediatly sends the message to clt2.

When only only clt2 is online:

    1. clt2 sends a request to the server to know if messages have been send for him/her.
    1. If yes, get those.

It works only if the server knows at any moment if the clients are online or not.

Hope it helps

  • Related