Make a P2P connection in 10 minutes

carloslfu

Carlos Galarza

Posted on March 19, 2018

Make a P2P connection in 10 minutes

Distributed Network

This is a short guide on how to make a P2P chat. My aim is to give you only a taste if you like I could write a deeper article explaining how all these things work. That said, let's start.

Preparation

The only thing you will need is the latest NodeJS and your favorite editor, mine is Visual Studio Code. Now create a folder for our project, open a command line, initialize an npm repo with npm init and install some libraries we will need with:



npm i --save discovery-swarm dat-swarm-defaults portfinder get-port


Enter fullscreen mode Exit fullscreen mode

Our first P2P connection

Let's start by doing a simple P2P connection, thanks to some great libraries from the Node.js community it is too simple:

Run this code in two consoles and this is it!. Now you can run it in other device right in your LAN and should work even without internet, also you can share and run this script in any other computer or device with internet around the world and it just works, so nice!

How it works?

This code uses the technology behind the Dat Project. All communications are decentralized and work over a P2P network.

...

I love feedback. Ask me questions, comment on your experience with P2P technologies and share your ideas! Thanks for reading :)

This series is possible thanks to the awesome tools delivered by the DatProject, Webtorrent and the NodeJS community.

Follow me on here and on Twitter if you want to know more about tech and distributed P2P networks: https://twitter.com/carloslfu

💖 💪 🙅 🚩
carloslfu
Carlos Galarza

Posted on March 19, 2018

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Make a P2P connection in 10 minutes
javascript Make a P2P connection in 10 minutes

March 19, 2018