Code Monkey home page Code Monkey logo

p2pstream's Introduction

p2pstream

This project is a peer to peer live streaming application software that uses centralized peer to peer architecture operating on an unstructured network topology. It is implemented in c++ using raw c++ sockets and uses pthread library for Multithreading. p2pstream uses peer-to-peer paradigm on top of the client-server model which explains how a peer is both a client and a server.

Installation :

 git clone https://github.com/adiitya/p2pstream.git
 cd ./p2pstream
 make

Note: libvlc, SFML, pthread libraries should be installed before installing this.

How it works:

  1. Start the centralServer - The backbone of the model.
        ./central <Own_IP/IP_of_central_server>
  1. Start the Peer(Client + Server)
		./server <Own_IP>
		./client <IP_of_centralServer>

Note : For now the user need to manually enter the the File to IP mapping (i.e Name of file ---> IP address of peers having the file - space separated).

Architecture

Model:

  • A central server listening for any request for a file from any peer(Client). It responds with the IP addresses of all the peers having the requested file, by looking up a map of file to IPs. While responding

  • The client then connects to these peers and starts downloading.

  • The peers online when requested for a file, responds with the file. A peer can serve multiple peers at the same time and can also download packets for streaming for itself. Note: The files to be served by a peer, should be in the server directory.

Classes

p2pstream uses OOP paradigm.

These are the core classes used by all the peer classes

Connection class is used by all the peers to establish connection with central-server or any other other peer.

  • When a peer wants to connect to another peer, this class needs the IP address and port of the peer to connect and create a connection object.
  • Since a peer can act as both clinet/server so, when a peer is listening for connections( Server part of a peer),the class takes a sockid as argument and creates a connection object with that peer for futher interactions. This peer can serve other peers on a different thread at the same time.

The Data class handles all the work related to reading and writing data:

Data will always transferred as stream of bytes. During sending/receiving it may be either a string (Eg. while searching for contents over various peers like movie or content name or any query to central server) or it can be a file to be downloaded or uploaded. So we have two derived data classes : BufferData and FileData inheriting Data class: So for sending or recieving as string we create a bufferData class object

	Data* dataObj = new BufferData(char_array, size_of_array);

And for sedning and recieving on or from a file simply creating a FileData object.

    Data* dataObj = new FileData(name_of_file, FileData::FTYPE::READ);

For reading and writing we just need to call the same functions of the Data class(The parent class) For sending or receiving, we will use the object of the connection class which takes as argument a Data object. So basically it can take any of the two data types defined above and handles them accordingly.

UML Diagram

uml classes

Implementation

  • p2pstream is implemented using raw C++ sockets.
  • It uses pthread library for Multithreading.
  • It uses libvlc for processing the data-received.
  • SFML is used for rendering the interface.

Demo

  1. Request by one Peer with IP of central-server(Peer asked for the file to be downloaded): client
  2. Response by central-server with the list of IPs having file: central
  3. Response by another peer with the file: server The test was successful with a peer serving multiple peers and downloading packets at the same time.
  4. Streaming video in SFML Player screen

Contribution

Feel free to file issues and submit pull requests โ€“ contributions are welcome.

License:

p2pstream is licensed under the MIT License.

p2pstream's People

Contributors

adiitya avatar akshaypatni2 avatar ankg avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.