A simple real-time chat application built with Python using the socket module for backend communication and (optionally) Flask for the web interface.
- Real-time messaging between multiple users
- Command-line client for chat
- Easy to set up and run locally
- Uses Python's standard
socketmodule for networking
To help you understand how the chat server works, here’s a visual overview of the communication sequence:
- The server is started using
python server.py. - It listens for incoming client connections on
127.0.0.1and the specified port. - For each client, it receives a username, validates it, and starts a new thread to handle messages from that client.
- When a client sends a message, the server broadcasts it to all connected clients and prints it on the server terminal.
- The client is started using
python clinet.py. - The user is prompted to enter a username.
- The client connects to the server and sends the username.
- The client can send messages to the server, which are then broadcast to all other clients.
- The client also listens for messages from the server and displays them in real time.
Below is a visual representation of how the client communicates with the server:
Below is an example screenshot showing the server and client running in separate terminals:
Left: Server terminal showing received messages. Right: Client terminal for sending and receiving messages.
- Python 3.x
-
Clone the repository:
git clone https://github.com/yourusername/Chat-Application.git cd Chat-Application -
(Optional) Install Flask if you plan to use a web interface later:
pip install Flask
If you want to use a different port, you can run the provided script to find a free port:
python to_find_a_free_port.pyUpdate the PORT variable in both server.py and clinet.py if you change the port.
python server.pyOpen a new terminal for each client and run:
python clinet.pyMake sure the HOST and PORT in clinet.py match those in server.py.
Each client will connect to the server and can send/receive messages in real time.
Chat-Application/
├── server.py # Chat server using sockets
├── clinet.py # Command-line chat client
├── to_find_a_free_port.py # Utility to find a free port
├── static/ # (For future Flask web interface)
├── templates/ # (For future Flask web interface)
├── chat_server_communication_sequence.png # Server communication diagram
├── client_server_communication_sequence.png # Client communication diagram
├── terminal_working_example.png # Screenshot of terminal working
└── README.md
- The server listens on
127.0.0.1(localhost), so only clients on the same machine can connect. - You can extend this project by adding a Flask web interface in the future.
This project is licensed under the MIT License.


