In a real-time messaging app, the client applications (such as web or mobile apps) communicate with the server using WebSocket. When a user sends a message, it is transmitted to the server and then the message is sent to the other client connected to it. The client receives the message in real time and is displayed on the UI of the user.

for more: https://www.mirrorfly.com/blog/how-to-build-a-real-time-chat-app/