Search code examples
connectionp2pfile-sharing

How to build a p2p connection between 2 devices like torrent


I want to build a system with 2 or more devices. Devices in the system can send files to each other using p2p, not through the server (files to be sent are not uploaded to the server)

To clear, suppose my system has 2 PCs placed in 2 different places (not LAN network and no static ip), they can share files with each other via the internet without a server. I do not want shared files uploaded to the server (no time and memory required).

Of course my system will still have a server and a database that will store data and transfer some important information between the two devices via sockets.

I searched a lot on the internet, and all I found was around the torrent network. I don't know how to build a system like torrent.

I have not decided which language or framework I will use (Java, C#, Python, NodeJS). Any suggestions on tutorial, languages, libraries, frameworks are welcome.

Thanks all


Solution

  • Since you have a server, it's much easier.

    1. Using your server to build a ICE structure to do NAT traversal

    2. You may need some machines to release the pressure of server when finding other nodes, so LSD and DHT are both recommanded.

    3. Using peer wire protocol to send files is really good.

    There is an open source project libtorrent which may be useful for you. I think you can just use some part of it to realise your design. As for language, libtorrent is written by C++, but it's not really important.