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 messageclient2
(clt2) that receives the message
When only clt1
is online and it sends a message:
-
- Store the message of
clt1
in theserver
.
- Store the message of
-
- When
clt2
reconnects, it sends a request to theserver
to get the messages.
- When
When both are online:
-
clt1
sends a message to theserver
.
-
- As the
server
knows thatclt2
is online, it immediatly sends the message toclt2
.
- As the
When only only clt2
is online:
-
clt2
sends a request to theserver
to know if messages have been send for him/her.
-
- If yes, get those.
It works only if the server
knows at any moment if the clients are online or not.
Hope it helps