Since the socket.io framework has components for both the server and the client, we will use these components to code our communication on both the sides. Events emitted on a socket on one side will be handled by the corresponding event handler on the other side. Socket.io is built so that both the sides can send messages or attach handlers to process the incoming messages.
Let's begin by understanding how the messages will flow. It is important to remember that "messages" here are not the actual messages sent and received by users of the chat system, but the messages used for communication by the client and the server. There will be two types of messages, as follows:
The system messages : These messages will be sent by our chat system to the client, like when the user is connected, when others connect, or when users disconnect. Let's identify it with
serverMessage
.The user messages : These messages will be sent by the client to the server and will actually carry the user...