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.
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.
- 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.
This brings up the server and two scripted clients (“Alice” and “Bob”) that exchange messages and exit.
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.
cd dockerized_version
docker compose down -v --remove-orphans
docker compose up --buildRun the server once, then attach two separate interactive clients (each in its own terminal).
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 -vTerminal 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 -vThe 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.
Run the server and two clients on three separate hosts inside the Mininet VM.
In the Mininet VM:
sudo mn --topo single,3 --macYou’ll enter the mininet> CLI with hosts h1, h2, h3.
If you have X forwarding configured:
mininet> xterm h1 h2 h3Alternatively, run commands inline by prefixing with the host name (shown below).
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/.
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 -c- 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.