简体   繁体   中英

Is it possible to create peer-to-peer connections in different network?

I want to create peer-to-peer connections between 2 nodejs client.

using websocket (dnode)

here is the limit:

  • nodejs client run at 2 pc which is in different network.
  • they don't have static ip (192.168.1.100 && 192.168.2.200) behind NAT or firewalls
  • no permission to change the mapping of router.
  • has only static web server in public network. (can change the file by human)
  • can install application at pc (win)

is it possible? thanks

May be you can use PeerJS to achieve your objectives. PeerJS simplifies WebRTC peer-to-peer data, video, and audio calls. PeerJS wraps the browser's WebRTC implementation to provide a complete, configurable, and easy-to-use peer-to-peer connection API. Equipped with nothing but an ID, a peer can create a P2P data or media stream connection to a remote peer.

Also to broker connections, PeerJS connects to a PeerServer . Note that no peer-to-peer data goes through the server; The server acts only as a connection broker.

If by peer to peer connection, you mean direct connection between the peers (ie, not via a server) then yes it is probably possible in theory in most cases. But I have never seen someone who has implemented the solution.

You would need to implement a NAT hole punching system for TCP connections (they are not always 100% successful because of technical constraints which can't be solved at the software layer). Then, you'd just need to implement the websocket protocol on top of this tcp connection.

If by peer to peer connection, your are ok that communication passes via a central server (with a public address), then yes it is possible too. Both peers just need to connect to the central server, and it should just transfert the traffic between both peer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM