GitHunt
R-

r-siddiq/Client_Server_Socket

UDP client/server demo in Python with two versions: Dockerized (portable, lightweight) and VM+Mininet (virtual network simulation), showcasing message passing, sockets, and network testing.

Client/Server Socket — VM (Mininet) & Dockerized Versions

This repository contains a simple UDP client/server application implemented in Python to demonstrate message passing over sockets. It ships in two runnable forms:

  1. Original (VM + Linux + Mininet) — Require a virtual network environment.
  2. Dockerized (no VM/Mininet required) — a lightweight, reproducible setup that runs anywhere Docker is available.

High-Level Overview

  • Protocol: UDP
  • Behavior: The server receives a sentence and returns the uppercase version of the same sentence.
  • Language: Python (standard library only; no third‑party dependencies)

Application Flow

  • Server starts, binds to a UDP port, waits for datagrams, converts to uppercase, and replies to the sender.
  • Client connects to the server address/port, takes user input (stdin), sends it as bytes, prints the response, and exits when the user types done.

Repository Layout

Below are the key directories and files expected for both versions.

Client_Server_Socket/
  README.md                              ← this file
  dockerized_version/
    docker-compose.yml
    run.sh                                ← helper to build+start server then attach client
    down.sh                               ← helper to tear everything down
    client/
      Dockerfile
      app/
        udp_client.py
    server/
      Dockerfile
      app/
        udp_server.py
  oracle_vm_mininet_version/
    udp_client.py                          ← used on h2 in Mininet
    udp_server.py                          ← used on h1 in Mininet

Code summaries

  • udp_server.py — Listens on UDP, uppercases incoming payloads, and replies.
  • udp_client.py — Connects via UDP to HOST:PORT, reads input until done, prints uppercased responses.

Note: In the original classroom submission, HOST and PORT were hard-coded. In the Dockerized version, these are read from environment variables for portability.


Dockerized Version

The Dockerized setup packages both client and server in containers and connects them on an isolated bridge network. No VM, Linux distro install, or Mininet needed.

Highlights

  • Separate images for server and client (server/Dockerfile, client/Dockerfile).
  • Environment-driven configuration: HOST and PORT are configurable via env vars.
  • docker-compose creates an isolated network and starts the server; the client is run interactively.
  • Helper scripts (run.sh, down.sh) for convenience on Unix-like shells. (Windows PowerShell scripts can be added as well.)

Quick Start (Dockerized)

Prerequisites: Docker Desktop (Windows/macOS) or Docker Engine (Linux). Ensure the daemon is running (docker version should show both client and server sections).

# from the dockerized version folder
docker compose build
docker compose up -d server
docker compose run --rm client
  • Type messages at the client prompt (e.g., hello) and you should receive uppercase echoes (HELLO).
  • Type done to exit the client.
  • Tear down the environment:
docker compose down -v

Configuration

  • Default port: 12345/udp
  • Server env: HOST=0.0.0.0, PORT=12345
  • Client env: HOST=server (Docker DNS name of the server service), PORT=12345
  • The compose file also assigns static IPs on a custom bridge network for clarity, but Docker DNS (server) is preferred.

Expected interaction

Input sentence: cst
Received: CST
Input sentence: is pRettY FuN !!!
Received: IS PRETTY FUN !!!

Notes

  • The client service resolves the server by name server via the Compose network.
  • Default port is 12345. You can -p 12345:12345/udp change in docker-compose.yml if needed.

Troubleshooting

  • Docker daemon not running
    Error like open //./pipe/docker_engine: The system cannot find the file specified.
    → Start Docker Desktop, wait for the whale icon to become steady, and retry.

  • Client can’t reach server
    Ensure the server container is running: docker ps, check logs: docker logs socket_server.

  • Windows + PowerShell + .sh scripts
    .sh scripts require Bash (Git Bash/WSL). Use the raw Docker commands in PowerShell instead.


Original VM + Linux + Mininet Version

This variant assumes you want to simulate a network topology with Mininet inside a Linux VM (e.g., Ubuntu) on Oracle VirtualBox.

Prerequisites

  • Oracle VirtualBox
  • Ubuntu (or similar) Linux distro installed in the VM
  • Mininet installed in the VM
  • Python 3.x

Typical Steps

  1. Boot the VM and start Mininet with the desired topology.
  2. Determine the server host IP and choose a UDP port.
  3. On one host namespace in Mininet, run udp_server.py; on another, run udp_client.py.
  4. Enter messages in the client terminal and verify uppercase echoes from the server.
  5. Stop the processes and shut down Mininet and/or the VM when finished.

Running with Oracle VirtualBox VM + Mininet

This version runs in a Mininet-based virtual network with two hosts.

1) Start Mininet with a default 2-host topology

sudo mn

This launches a basic network with h1 and h2 connected to switch s1.

2) Identify/confirm host IPs (default topology)

h1: 10.0.0.1/8
h2: 10.0.0.2/8

You can verify inside Mininet:

mininet> h1 ifconfig
mininet> h2 ifconfig

3) Copy the VM versions onto the hosts

Place these two files on the Mininet VM (e.g., in the working directory you’ll use inside Mininet):

  • oracle_vm_mininet_version/udp_server.py
  • oracle_vm_mininet_version/udp_client.py

4) Launch the server on h1 (background) and the client on h2

From the Mininet CLI:

mininet> h1 python3 udp_server.py &
mininet> h2 python3 udp_client.py

Now type test inputs at the client prompt. Type done to stop the client. To stop the server, return to Mininet and kill its job or exit Mininet.

Sample session

mininet> h1 python3 udp_server.py &
mininet> h2 python3 udp_client.py
Input sentence: hello
Received: HELLO
Input sentence: socket
Received: SOCKET
Input sentence: is pRettY FuN !!!
Received: IS PRETTY FUN !!!

5) Troubleshooting (VM/Mininet)

  • Ensure you ran the server first on h1 and the client on h2.
  • Confirm HOST and PORT values match between client/server.
  • If you changed topology/IPs, update the constants accordingly.
  • If the client seems stuck, make sure you are using python3.
r-siddiq/Client_Server_Socket | GitHunt