A Python-based hybrid networking system that combines Client-to-Server (C2S) and Peer-to-Peer (P2P) architectures to improve file-sharing scalability, load distribution, and fault tolerance. The system uses a central server for control and peer cache servers (CDN peers) for overflow handling and caching.
Traditional Client-to-Server (C2S) file-sharing systems suffer from server overload as the number of clients increases, while pure Peer-to-Peer (P2P) systems lack centralized control.
This project implements a hybrid solution where:
- Clients first request files from a central server.
- When the server reaches its maximum connection limit, clients are redirected to CDN (peer cache) servers.
- Peer servers cache previously fetched files and serve future requests directly.
This hybrid design reduces server load and enhances network robustness and scalability.
- Language: Python 3.x
- Networking: TCP using Python
socketmodule - Concurrency: Multi-threading using
threading - Architecture: Hybrid Client–Server and Peer-to-Peer
- File Handling: Binary file transfer with EOF markers
TCPServer.py— Central server implementation (handles file requests, enforces maximum connections, and redirects clients to CDN peers).TCPClient.py— Client implementation (requests files and connects to CDN peers when redirected).Cdn_Peer.py— CDN / peer cache server (checks cache, fetches missing files from server, and stores them for reuse).
The system consists of three main components:
- Accepts initial client connections
- Serves files from the main repository (
./data) - Monitors active connections
- Redirects clients to CDN peers when overloaded
- Receives redirected client requests
- Maintains a local cache (
./cache) - Fetches missing files from the main server
- Stores files for future use
- Sends file requests to the central server
- Switches to CDN peers when redirected
- Downloads and saves files locally
Hybrid_C2S-P2P_FileSharing/
│
├── TCPServer.py # Central server
├── TCPClient.py # Client
├── Cdn_Peer.py # CDN / peer cache server
└── README.md # Documentation
- Client sends a file request to the main server.
- Server checks the number of active connections.
- If under the limit → file is served directly.
- If the limit is reached → client is redirected to a CDN peer.
- CDN peer checks its cache:
- If file exists → sends it to the client.
- If not → fetches it from the server, caches it, and sends it.
- Client receives and saves the file.
The hybrid C2S–P2P approach provides centralized control while offering decentralized scalability. Redirecting overflow clients to peer cache servers reduces the load on the primary server and speeds file delivery by leveraging cached copies. This design is suitable for local networks or lab-scale deployments where server resources are constrained. (See final slide for the project conclusion).