r-siddiq/Thread_Chat
Thread Chat is a TCP-based two-client chat service with Dockerized automation and interactive demos, plus Mininet walkthrough, showcasing sockets, concurrency, health checks, and containerized workflows.
Thread Chat — TCP Client/Server
A simple two-client chat service over TCP. This repo includes:
- A Dockerized setup for an automated demo with scripted clients.
- An interactive (individualized) Docker workflow where each client runs in its own terminal.
- A Mininet walkthrough for running the server and two clients on separate hosts in an Oracle VirtualBox Linux VM with Mininet.
Repository Layout
Thread_Chat/
├─ dockerized_version/
│ ├─ chat_server.py
│ ├─ chat_client.py
│ ├─ scripted_client.py
│ ├─ docker-compose.yml
│ ├─ Dockerfile
│ ├─ scripts/
│ │ ├─ client1_messages.txt
│ │ └─ client2_messages.txt
│ ├─ Makefile # optional convenience aliases
│ └─ tmux_interactive.sh # tmux helper for split-pane runs
└─ oracle_vm_mininet_version/
├─ chat_server.py
└─ chat_client.py
Default server port: 12000/TCP.
Prerequisites
- Docker Desktop with Compose v2 enabled (Windows/macOS) or Docker Engine + Compose plugin (Linux).
- PowerShell (Windows) or Git Bash / WSL bash (Windows) or any bash shell (macOS/Linux).
- Python 3.11+ is baked into the containers. For Mininet runs you’ll need Python 3.x in the VM.
Quick Start — Automated Demo (Dockerized)
This brings up the server and two scripted clients (“Alice” and “Bob”) that exchange messages and exit.
PowerShell
cd .\dockerized_version
docker compose down -v --remove-orphans
docker compose up --buildExpected: the server announces readiness, both clients connect, exchange the scripted lines, and exit with code 0. Stop with Ctrl+C.
Git Bash / WSL
cd dockerized_version
docker compose down -v --remove-orphans
docker compose up --buildInteractive (Individualized) Clients — Dockerized
Run the server once, then attach two separate interactive clients (each in its own terminal).
PowerShell
Terminal 1 — Server (detached):
cd .\dockerized_version
docker compose up --build -d serverTerminal 2 — Client #1 (interactive):
cd .\dockerized_version
docker compose run --rm -it --name alice client1_demo python chat_client.py --server server --port 12000Terminal 3 — Client #2 (interactive):
cd .\dockerized_version
docker compose run --rm -it --name bob client2_demo python chat_client.py --server server --port 12000Type a username when prompted, then chat. Type bye to leave.
Shutdown:
docker compose down -vGit Bash / WSL
Terminal 1 — Server (detached):
cd dockerized_version
docker compose up --build -d serverTerminal 2 — Client #1:
cd dockerized_version
docker compose run --rm -it --name alice client1_demo python chat_client.py --server server --port 12000Terminal 3 — Client #2:
cd dockerized_version
docker compose run --rm -it --name bob client2_demo python chat_client.py --server server --port 12000Shutdown:
docker compose down -vOptional: tmux Split-Pane Runner (Git Bash / WSL)
The tmux_interactive.sh helper opens a tmux session with panes for the server and two clients.
cd dockerized_version
chmod +x tmux_interactive.sh
./tmux_interactive.shRequirements: tmux available in your shell (sudo apt-get install tmux in WSL/Ubuntu). Close panes or press Ctrl+b then : and type kill-session to exit.
Oracle VirtualBox — Mininet Walkthrough
Run the server and two clients on three separate hosts inside the Mininet VM.
1) Start a 3-host topology
In the Mininet VM:
sudo mn --topo single,3 --macYou’ll enter the mininet> CLI with hosts h1, h2, h3.
2) Open terminals for each host (xterm)
If you have X forwarding configured:
mininet> xterm h1 h2 h3Alternatively, run commands inline by prefixing with the host name (shown below).
3) Place the app files on the VM
Copy chat_server.py and chat_client.py from oracle_vm_mininet_version/ into the VM (e.g., via shared folders or scp). Assume they are in /home/mininet/chat/.
4) Run the server and clients
Server on h1:
mininet> h1 python3 /home/mininet/chat/chat_server.pyClient on h2:
mininet> h2 python3 /home/mininet/chat/chat_client.pyClient on h3:
mininet> h3 python3 /home/mininet/chat/chat_client.pyEnter usernames and chat between h2 and h3. Type bye from a client to leave; the server stays up to serve subsequent sessions (if your server variant is configured to remain running).
Stop Mininet:
mininet> exit
sudo mn -cTroubleshooting
- Server marked unhealthy in Compose: ensure the healthcheck in
docker-compose.ymluses a valid command (e.g., a small Python socket connect to127.0.0.1:12000) and that the server is listening before clients start. ConnectionRefusedErrorfrom a client: the client started before the server was ready. Usedepends_on: condition: service_healthyfor demo clients, or start the server first for interactive runs.- Windows line endings: scripts expect LF line endings. If you see odd behavior, convert with
dos2unix.