Skip to content

Dayan135/CommunicationHackaton

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 

Repository files navigation

CommunicationHackaton

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.


Quick summary

  • 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

How it works (high-level)

  1. 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.
  2. A client sniffs for those offer packets using Scapy. When an offer is detected the client reads the server IP and offered ports.
  3. 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.
  4. 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.


Prerequisites

  • 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.


Install (recommended steps)

  1. Clone the repository
git clone git@github.com:Dayan135/CommunicationHackaton.git
cd CommunicationHackaton
  1. 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)
  1. 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.


Running the demo

Open two terminals (or two machines on the same LAN). First start the server, then the client.

  1. Start the server
python3 Hackathon/serve.py

The 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.
  1. Start the client (requires sniff privileges)
sudo python3 Hackathon/client.py

The 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.


Files in this repo (relevant)

  • 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)

Notes, caveats and suggestions

  • 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_Store and .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.

Possible next improvements

  • Add a requirements.txt and CI job for linting/tests.
  • Add an argparse CLI 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.

License & attribution

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.


Contact

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.sh to start both. Tell me which of these you prefer and I will prepare the files.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages