Skip to content

Hygrevan-343/Hybrid_C2S-P2P_FileSharing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Hybrid C2S & P2P File Sharing System

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.


Project Overview

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.


Tech Stack

  • Language: Python 3.x
  • Networking: TCP using Python socket module
  • Concurrency: Multi-threading using threading
  • Architecture: Hybrid Client–Server and Peer-to-Peer
  • File Handling: Binary file transfer with EOF markers

📁 Components / Files

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

System Architecture

The system consists of three main components:

1. Central Server (C2S)

  • Accepts initial client connections
  • Serves files from the main repository (./data)
  • Monitors active connections
  • Redirects clients to CDN peers when overloaded

2. CDN / Peer Cache Server

  • Receives redirected client requests
  • Maintains a local cache (./cache)
  • Fetches missing files from the main server
  • Stores files for future use

3. Client

  • Sends file requests to the central server
  • Switches to CDN peers when redirected
  • Downloads and saves files locally

Project Structure

Hybrid_C2S-P2P_FileSharing/
│
├── TCPServer.py   # Central server
├── TCPClient.py   # Client
├── Cdn_Peer.py    # CDN / peer cache server
└── README.md      # Documentation

How It Works

  1. Client sends a file request to the main server.
  2. Server checks the number of active connections.
  3. If under the limit → file is served directly.
  4. If the limit is reached → client is redirected to a CDN peer.
  5. 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.
  6. Client receives and saves the file.
C2S_P2P - Presentation - A12 - CN

Conclusion

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

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages