A simple, real-time command-line chat application built with Python. Connect multiple clients to a central server and chat with others or send private messages.
- 🌐 Multi-client support
- 💬 Public messaging (broadcast to all users)
- 💌 Private messaging between users
- 👥 View connected users
- 📝 Change username on the fly
- 📜 View chat history
- 🎯 Simple command-based interface
- Python 3.6 or higher
- No external dependencies (uses standard library only)
Open a terminal and run:
python server.py 127.0.0.1 5000Arguments:
127.0.0.1→ Server IP address (localhost for local testing)5000→ Port number (use any available port)
Expected output:
Server started on 127.0.0.1:5000
Waiting for clients...
Open a new terminal window for each client:
python client.py 127.0.0.1 5000Arguments:
127.0.0.1→ Server IP address (same as server)5000→ Port number (same as server)
When prompted, enter a username (e.g., Alice, Bob).
💡 Tip: Open multiple terminal windows to simulate different users chatting.
Once connected, clients can use these commands:
| Command | Description | Example |
|---|---|---|
/users |
Show all connected users | /users |
/pm <username> <message> |
Send a private message | /pm Bob Hey there! |
/name <newname> |
Change your username | /name Alice123 |
/history |
Show last 50 chat messages | /history |
/exit |
Disconnect gracefully | /exit |
/help |
Show available commands | /help |
Public message (to everyone):
Hello everyone!
Private message (to specific user):
/pm Bob Hey Bob, how are you?
chat-cli-app/
├── server.py # Server application
├── client.py # Client application
└── README.md # This file
Terminal 1 (Server):
$ python server.py 127.0.0.1 5000
Server started on 127.0.0.1:5000
Waiting for clients...Terminal 2 (Client 1):
$ python client.py 127.0.0.1 5000
Enter your username: Alice
Connected to server!
Alice: Hello everyone!Terminal 3 (Client 2):
$ python client.py 127.0.0.1 5000
Enter your username: Bob
Connected to server!
Bob: Hi Alice!
Bob: /pm Alice Nice to meet you privatelyTo connect clients from different computers:
-
On the server computer:
- Find your IP address:
- Linux/Mac:
ifconfigorip addr - Windows:
ipconfig
- Linux/Mac:
- Start server with your IP:
python server.py 192.168.1.100 5000
- Find your IP address:
-
On client computers:
- Connect using server's IP:
python client.py 192.168.1.100 5000
- Connect using server's IP:
This is a basic chat application designed for learning and local network use. It does not include:
- Encryption
- Authentication
- Input sanitization
- Rate limiting
"Connection refused" error:
- Ensure the server is running first
- Check that IP address and port match on both server and client
- Verify firewall isn't blocking the connection
"Address already in use" error:
- The port is already in use
- Try a different port number or close the application using that port
This project is open source and available for educational purposes.
Feel free to fork this project and add new features such as:
- Message encryption
- File sharing
- Emoji support
- Chat rooms/channels
- User authentication