A peer-to-peer file sharing system built in C++, similar to BitTorrent. Peers can share and download files directly from each other. A central server acts as a tracker — it only stores metadata (who has what), never the actual file data.
[Server - Tracker] ← maintains file registry only
↑ ↑
[Peer 1] [Peer 2] ← transfer files directly between each other
- Server: Tracks which peers have which files/chunks. Stores nothing on disk.
- Client (Peer): Shares local files and downloads files directly from other peers.
- A peer registers its files with the server (
sharecommand). - Another peer asks the server for available files (
showcommand). - The server responds with peer IPs and chunk locations.
- The downloading peer connects directly to source peers and downloads chunks in parallel.
- Chunks are reassembled into the final file locally.
Files are split into 1024-byte chunks. Different chunks can be downloaded simultaneously from different peers, improving speed.
- g++ with C++11 support
- POSIX-compatible OS (Linux / macOS)
git clone <repo-url>
cd p2p-file-sharing
makeThis produces two binaries: server and client.
./serverOutput: Server started on port 8080
./client 8082./client 8083Each peer must use a different port number.
| Command | Description |
|---|---|
show |
List all files available to download |
share N file1 file2 ... |
Share N files from the current directory |
download filename |
Download a file from other peers |
Peer 1 — share a file:
share 1 notes.pdf
Peer 2 — list and download:
show
download notes.pdf
- The file you want to share must be in the same directory from which you run
./client. - Server data is in-memory only — restarting the server clears all registered files. Peers must re-register their files after a server restart.
- Downloaded files are saved to disk permanently and are not affected by server restarts.
- If a download is interrupted, a
.logfile tracks completed chunks so the download can resume.
Edit SERVER_IP in both server.hpp and peers.hpp:
#define SERVER_IP "your.server.ip"Then recompile and run ./server on the server machine and ./client <port> on each peer machine.
Peers must have publicly reachable IPs (or be on the same LAN) since file transfers are direct peer-to-peer — they do not go through the server.
| Request | Description |
|---|---|
| Register Request | Peer tells server which files it wants to share |
| File List Request | Peer asks server for all available files |
| File Locations Request | Peer asks server for IPs/ports of peers that have a specific file |
| Chunk Register Request | Peer notifies server after receiving a new chunk |
| File Chunk Request | Peer requests a specific chunk directly from another peer |
make clean