Virtual Expo 2025

P2P File Sharing

Year Long Project CompSoc

P2P File Sharing

Aim:

The primary aim of this project is to develop a real-time, peer-to-peer (P2P) file sharing and messaging web application that enables users to communicate and exchange files directly without relying on centralized servers for data transfer.

Introduction:

In today's digital era, the demand for secure and efficient file sharing has increased substantially. Traditional platforms often rely on centralized servers, which can compromise user privacy and introduce latency. To address these limitations, we have developed a peer-to-peer (P2P) file sharing and messaging platform that operates in real time.

Our system allows users to join both private and public rooms, enabling seamless file transfers and instant messaging through a browser interface. The platform is built using React for the frontend, with WebRTC handling direct P2P connections and WebSockets managing real-time communication.

The primary objective of this project is to deliver a scalable, decentralized solution that enhances user experience while maintaining privacy and performance.

Technologies Used:

HTML, CSS, Javascript, Typescript React with vite

WebRTC

Node.js with Express

WebSockets

Implementation:

Room Creation and Joining:

To initiate communication, the application allows users to either create a private room or join an existing one. A unique Room ID is generated when a user creates a private room, which can be shared with others for them to join. Public rooms are also supported, where no ID is required. These rooms are categorized under different genres such as “Tech”, “Gaming”, or “General”, helping users connect based on shared interests. Room management is handled using WebSockets. Upon joining, a user emits a socket event that informs the backend of their presence. The server then notifies all other clients in the room, prompting the establishment of peer-to-peer connections.

Peer-to-Peer connection with WebRTC:

Once users are in the same room, WebRTC (Web Real-Time Communication) is used to establish direct P2P connections between each pair of clients. However, WebRTC cannot function independently; it requires a signaling mechanism to initiate and maintain connections. This signaling is handled through WebSockets. When a user joins a room, they send a ready signal through WebSocket. The signaling process involves the exchange of Session Description Protocol (SDP) messages and ICE (Interactive Connectivity Establishment) candidates. The server facilitates this exchange, allowing users to learn about each other's IP addresses and network capabilities.

After signaling, WebRTC establishes a secure and encrypted data channel for direct communication.

File Transfer Mechanism:

File sharing is one of the core functionalities of the application. When a user selects a file, it is read into memory and, if necessary, split into manageable chunks. This is particularly useful for large files, ensuring that transmission over the data channel remains stable and does not overwhelm the receiving client. The chunks are transmitted in sequence over the WebRTC data channel. On the receiving end, the chunks are buffered, reassembled, and then presented to the user with an option to download the file. The implementation handles file metadata such as filename, size, and type to ensure accurate reconstruction.

Real-Time Messaging Using WebSockets:

In addition to file sharing, users can communicate via real-time text messages. The messaging system is implemented using WebSocket connections. When a message is typed and sent by a user, it is transmitted to the server via a socket event. The server then broadcasts this message to all participants in the room. The frontend React application maintains a local message state, which is updated dynamically upon receiving new messages. Each message is accompanied by a timestamp and the sender’s identification, and messages are displayed in an aesthetically styled chat window. This messaging system plays a critical role in enhancing interactivity within the application, especially in public rooms where users may want to coordinate before transferring files.

Scalability Considerations:

The application is designed with scalability in mind. Because the actual file transfer occurs peer-to-peer, the server's workload is minimal, as it is only responsible for signaling and message routing. This architecture significantly reduces bandwidth and processing demands on the server. However, in large rooms with many participants, the number of peer connections increases exponentially (mesh topology), which could strain client resources. To address this, future iterations may incorporate Selective Forwarding Units (SFUs) or media servers for more scalable communication patterns.

Screenshots:

Home Page
Home Page

 

 

 

 

 

 

 

Create Room Page
Join Room Page
Room Page
Used to send files from user to user and can chat with other users in the room.

Results:

The developed application successfully achieves the primary goals of peer-to-peer file sharing and real-time communication. Through rigorous testing and multiple use-case scenarios, the following key results were observed:

Peer-to-Peer File Transfer: Users were able to transfer files directly without server involvement after the initial signaling. The file transfer was quick and stable for small to moderately large files (e.g., up to 100 MB).
 

Real-Time Messaging: Chat messages were transmitted instantly between users in a room using WebSockets, ensuring smooth and continuous communication.
 

Room-Based Architecture: Both public and private rooms functioned as expected. Users could join rooms using a unique ID or select from predefined genres.
 

Multi-User Support: The system handled multiple users within a room efficiently, establishing direct connections between peers using WebRTC.
 

Responsive Interface: The React-based frontend provided a dynamic and responsive user interface that adjusted to user interactions in real time.

 

Conclusions:

The project demonstrates the successful integration of modern web technologies to create a real-time, decentralized communication platform. By utilizing WebRTC and WebSockets, the application enables users to share files and chat in real-time, all within the browser, without needing external software or centralized servers for data handling. This implementation validates the potential of peer-to-peer architectures in reducing server load, improving scalability, and enhancing user privacy. Additionally, the system's room-based model makes it intuitive and suitable for various use cases like collaborative workspaces, study groups, and casual file sharing.

 

Link to Project: https://github.com/kira-yoshikage104/webRTC-frontend

 

Mentors:

Kumaara

Madhav

Mentees:

Shishir

Nakul

Purva


 


 

Report Information

Explore More Projects

View All 2025 Projects