A lightweight network benchmarking / discovery demo created during a hackathon by Dayan135.
This prototype demonstrates a simple service discovery (UDP broadcast offers) and file-data transfer over both UDP and TCP. It contains two main scripts under the Hackathon/ folder:
Hackathon/serve.py— a server that broadcasts offers and serves data over UDP and TCP.Hackathon/client.py— a client that sniffs for broadcast offers (using Scapy), then performs UDP and/or TCP transfers to measure throughput and packet loss.
This README fills in the repository's key details and run instructions.
- Language: Python 3
- Main dependencies: scapy, netifaces
- Purpose: demo of network discovery (broadcast offers) and simple data transfer benchmarking
- Folder:
Hackathon/contains the working prototype
- The server periodically broadcasts an "offer" UDP packet to local network broadcast addresses. The offer contains a "magic cookie", message type, UDP port and TCP port.
- A client sniffs for those offer packets using Scapy. When an offer is detected the client reads the server IP and offered ports.
- The client requests a transfer:
- For UDP: sends a request packet containing the magic cookie, request message type and requested file size. The server responds with segmented UDP payload packets that include sequence numbers so the client can measure packet loss and throughput.
- For TCP: the client opens a TCP connection, sends the requested file size, and the server streams the requested number of bytes.
- Both client and server print statistics (transfer speed, loss, etc.).
Key protocol constants (as defined in the scripts):
- MAGIC_COOKIE = 0xabcddcba
- MESSAGE_TYPE_OFFER = 0x2
- MESSAGE_TYPE_REQUEST = 0x3
- PAYLOAD_TYPE = 0x4
- BUFFER_SIZE = 1024
See the packaged code for exact struct packing/unpacking formats.
- Python 3.8+ recommended
- pip (or equivalent) to install Python packages
- Linux/macOS: running the client sniff (Scapy) typically requires elevated privileges (raw sockets). On Linux, run the client as root or with sudo, or grant appropriate capabilities to the Python binary.
- libpcap / WinPcap / Npcap may be required on some platforms for packet sniffing.
Recommended: use a virtual environment.
- Clone the repository
git clone git@github.com:Dayan135/CommunicationHackaton.git
cd CommunicationHackaton- Create and activate a virtual environment (optional but recommended)
python3 -m venv .venv
source .venv/bin/activate # Linux / macOS
.\.venv\Scripts\Activate # Windows (PowerShell/Cmd)- Install required Python packages
pip install scapy netifaces(Optional) Create a requirements.txt with:
scapy
netifaces
and then pip install -r requirements.txt.
Note: On some systems Scapy installation may require system packages (libpcap headers). If you see install errors, check your OS package manager for libpcap/pcap-dev.
Open two terminals (or two machines on the same LAN). First start the server, then the client.
- Start the server
python3 Hackathon/serve.pyThe server will:
- Bind ephemeral TCP and UDP sockets (it selects available ports).
- Print the TCP/UDP ports it's listening on.
- Start broadcasting offer packets on detected broadcast addresses.
- Serve incoming TCP connections and UDP requests.
- Start the client (requires sniff privileges)
sudo python3 Hackathon/client.pyThe client will:
- Prompt for the desired file size (in bytes), number of TCP connections and number of UDP connections to open.
- Sniff for broadcast offers (for a short timeout).
- For an offer found, connect to the server and run the requested transfers in parallel, printing throughput and packet-loss statistics per connection.
Example client inputs:
Enter the file size (in bytes): 1048576 # 1 MiB
Enter the number of TCP connections: 1
Enter the number of UDP connections: 1
When complete, the client prints summary stats and resumes listening for future offers.
- Hackathon/serve.py — server implementation (UDP broadcast + TCP/UDP transfer)
- Hackathon/client.py — client implementation (Scapy sniff + TCP/UDP measurement)
- .DS_Store and .idea/ — IDE artifacts (you may want to add a .gitignore)
- The client uses Scapy for sniffing broadcast packets. Scapy typically requires elevated privileges (sudo) or appropriate capabilities. Running as root is the simplest approach for testing on local machines.
- The scripts use ephemeral ports (they bind to port 0), so they will print the actual ports in use at runtime.
- There are
.DS_Storeand.idea/files present; consider adding a.gitignore:.DS_Store .idea/ __pycache__/ .venv/ - This is a prototype written for a hackathon — not production-grade networking code. It intentionally keeps things simple (no authentication, no retransmission for UDP, fixed payloads).
- If you plan to extend it: add CLI flags (argparse), configurable interface selection, logging, and tests.
- Add a
requirements.txtand CI job for linting/tests. - Add an
argparseCLI for server and client options (ports, interface, verbosity). - Replace raw Scapy sniffing with a cross-platform discovery mechanism if you need Windows support without Npcap.
- Add timeouts, retries and optional FEC for UDP transfers to reduce packet loss impact.
- Provide a small HTML/JS frontend to display transfer statistics in real time.
This repository is a hackathon prototype created by Dayan135. No license file is included in the repo — if you want an explicit license (MIT, Apache-2.0, etc.), add a LICENSE file and update this README.
Author: Dayan135 — https://github.com/Dayan135
If you'd like, I can:
- Open a PR that adds a
requirements.txt, a.gitignore, and this README into the repository. - Convert the server and client to accept CLI args and create a simple
run.shto start both. Tell me which of these you prefer and I will prepare the files.