DEV Community

Make a P2P connection in 10 minutes

Carlos Galarza on March 19, 2018

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...
Collapse
 
Sloan, the sloth mascot
Comment deleted
Collapse
 
carloslfu profile image
Carlos Galarza

Of course, Rinay, email me with more details or some code I can find a moment to help you. Sorry for the late response I last month I was busy.

Collapse
 
menakalak profile image
menaka lakshan

hi Carlos Galarza this is great as i expected. but i have small problem here. when i run this script on two different computers this will not works as expected. can you plz help me.

Collapse
 
carloslfu profile image
Carlos Galarza

Of course, I will email you.

Collapse
 
daaadyaaar profile image
daaadyaaar

Could you share this concept for me as well, I would like to use your solution between some valid computers IP on the internet or a bigger network.
Thanks

Thread Thread
 
carloslfu profile image
Carlos Galarza

I this code doesn't work for you I recommend you to use dev.to/carloslfu/comment/68ih. You don't need to put the computers IP in the code. Computers are connected with each other using the channel name:

/**
 * The channel we are connecting to.
 * Peers should discover other peers in this channel
 */
sw.join('our-fun-channel-name')

Hope it helps

Thread Thread
 
daaadyaaar profile image
daaadyaaar

Thanks for replying me Carlos.

Collapse
 
jake profile image
Jake Casto

Great Article! Very brief and got right to the point, loved it. How would you go about creating a P2P connection on remote (non-local) devices?

Collapse
 
carloslfu profile image
Carlos Galarza

Hi Jake, thanks! If you run the script in two remote computer with internet it works. I have updated the article for clarifying it. I am glad you liked the article :)

Collapse
 
hushino32 profile image
Hushino

Not work, any example of how peer_id: TCP_Connection works?

Collapse
 
carloslfu profile image
Carlos Galarza

If this implementation sometimes doesn't work is because of some issues with the discovery-swarm library. Fortunately, Hyperswarm was released recently. It implements a more reliable way of doing peer discovery. So, if you are experimenting issues try to use it now, this article pfrazee.hashbase.io/blog/hyperswarm about Hyperswarm includes a code example and here is the GitHub repo with some docs: github.com/hyperswarm/discovery.

Collapse
 
viktor62yt profile image
Viktor 62

Hi Carlos! I have a problem. after I start the 2 consoles, both say that they connected, but I can't write any messages. Please help me!

Collapse
 
shivarajrs007 profile image
shivaraja

Hi Carlos I want build p2p connection .which package are suitable? Tell me.