Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

A Python command-line LAN chat application with multi-user support, private messaging, and chat logging.

Notifications You must be signed in to change notification settings

abdullahmia/cli-chat-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

💬 CLI Chat Application

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.

✨ Features

  • 🌐 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

📋 Requirements

  • Python 3.6 or higher
  • No external dependencies (uses standard library only)

🚀 Getting Started

1️⃣ Start the Server

Open a terminal and run:

python server.py 127.0.0.1 5000

Arguments:

  • 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...

2️⃣ Connect Clients

Open a new terminal window for each client:

python client.py 127.0.0.1 5000

Arguments:

  • 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.

🎮 Commands

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

💬 Sending Messages

Public message (to everyone):

Hello everyone!

Private message (to specific user):

/pm Bob Hey Bob, how are you?

📁 Project Structure

chat-cli-app/
├── server.py          # Server application
├── client.py          # Client application
└── README.md          # This file

🔧 Usage Examples

Example Session

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 privately

🌐 Remote Connection

To connect clients from different computers:

  1. On the server computer:

    • Find your IP address:
      • Linux/Mac: ifconfig or ip addr
      • Windows: ipconfig
    • Start server with your IP:
      python server.py 192.168.1.100 5000
  2. On client computers:

    • Connect using server's IP:
      python client.py 192.168.1.100 5000

🛡️ Security Note

This is a basic chat application designed for learning and local network use. It does not include:

  • Encryption
  • Authentication
  • Input sanitization
  • Rate limiting

⚠️ Do not use on untrusted networks or expose to the internet without proper security measures.

🐛 Troubleshooting

"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

📝 License

This project is open source and available for educational purposes.

🤝 Contributing

Feel free to fork this project and add new features such as:

  • Message encryption
  • File sharing
  • Emoji support
  • Chat rooms/channels
  • User authentication

About

A Python command-line LAN chat application with multi-user support, private messaging, and chat logging.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages