A chat system (instant messaging) allows two or more people to contact each other through a network.
It is possible to communicate on different types of networks:
A chat application called "client-server" is composed of two applications:
EasyChat is a client-server application that allows users to communicate with each other over the Internet.
EasyChat is therefore composed of a client program ("ClientApplication") and a server ("ServerApplication").
The two applications that make up EasyChat are built using a "MVC" pattern for "Model View Controller".
By following this pattern:
The first part of the application is a program that runs on a server. After starting, the server-side program listens to incoming connections in a loop: a message "Waiting for a connection..." is displayed.
The second part of the application is the client program that the user runs from his machine (desktop, laptop, smartphone). The interface of the application looks like this:
When the client application opens, the login page is displayed.
To connect, you must enter a nickname, the address of the chat server (server that runs the server application) and click on the login button.
First, let's introduce the interface:
Now that the user has logged in under his nickname (here, John), he decides to send the message "Hello, I'm John" to the server.
The server (console window with black background) has received John's message. It is about to broadcast John's message to all connected users. Unfortunately John is currently the only one connected to the chat server.
So we will make sure that a second client connects to the chat server so that it can have a conversation with John. For the sake of this example, user Doe decides to connect to the chat.
Doe successfully connects and realizes that he is the number two customer. He decides to send a greeting to John "Hello John, how are you?"
At this point, the server receives the message and resends it to the connected users, John and Doe. Thus, John successfully received Doe's message and was able to respond, "Fine. Let's go to San Francisco".
In this article, the example used shows that the client connects to the server at address 127.0.0.0.1, i.e. "localhost" or the machine on which we are working locally (e.g. our personal computer).
The client application can work very well with any IPv4 address: its operation is not limited to a single machine but to an entire network.
In particular, I recommend that you test the application on a local network with at least:
Of course, there are many improvements that can be made to this application: