I am writing a proof of concept application to allow several computers to communicate with each other and control hardware that is attached to them. I would like to use Socket.IO or something like it for the connection , but I often want to send data directly from one socket client to another instead of to the socket server. This is mostly to save network traffic. Is this possible?
-
1See http://stackoverflow.com/questions/7022383/how-can-i-make-a-browser-to-browser-peer-to-peer-connection – Frank van Puffelen Sep 05 '14 at 19:47
-
there are newer RTC data methods that can almost do what you describe (they still need temporary access to a central server to handshake) – dandavis Sep 05 '14 at 19:51
-
Imagine going to some (hacked) site and suddenly your browser acts like a server, responding to web sockets request – Alvin K. Sep 05 '14 at 20:23
-
Maybe [PeerJS](http://peerjs.com/) is what you are looking for. – niekas Jan 19 '15 at 14:14
2 Answers
It looks like your answer might be WebRTC, described here:
Do websockets allow for p2p (browser to browser) communication?
From an answer in the article: "The WebRTC protocol and API is making rapid progress and allows a Data Channel to be established between two peers (you still may need a STUN/TURN server for the initial NAT traversal and setup)."
-
The answer you refered to is oudated. The guy wrote in 2010 that _The WebRTC protocol and API is making rapid progress_. It was almost 5 years ago! – niekas Jan 19 '15 at 14:08
There is a github project called socket.io-p2p which comes with a demo chat application that starts out brokered by a server but then switches to WebRTC.
The current link is https://github.com/socketio/socket.io-p2p . That seems unlikely to disappear any time soon, but, in case it does at some future point, you should be able to find a clone/fork somewhere by knowing the socket.io-p2p name. (It's under the MIT license.)

- 832
- 11
- 21