A lightweight, terminal-based chat application built using Python's native socket and threading libraries. This project implements a structural room system where clients can either create a new room with a custom code or join an existing one to chat in pairs.
- Dynamic Room System: Create or join specific chat rooms using unique text codes.
- Multi-Threaded Architecture: Handles multiple concurrent client connections without blocking the server or input streams.
- Race-Condition Safe: Utilizes
threading.Lock()to secure shared resources and prevent thread collisions. - Auto-Cleanup: Automatically destroys empty rooms and frees up system memory when clients disconnect.
- Lightweight & Efficient: Low memory and CPU usage, perfect for minimal desktop environments.
- Language: Python 3
- Core Libraries:
socket,threading,sys - Architecture: Client-Server Model, Low-Level TCP Networking, Concurrency Management.
First, run the server script to start listening for incoming connections on port 5000:
python server.pyOpen two separate terminal windows and run the client script in each:
python client.py-
Client 1: Selects create (or type 1) -> Enters room code (e.g., rahasia).
-
Client 2: Selects join (or type 2) -> Enters the same room code (rahasia).
Chat: Once connected, type your messages and hit Enter. Type exit to safely close the connection.