Do websockets allow for p2p (browser to browser) communication?
No. Browsers can only initiate WebSockets connections, not receive them. The W3C browser API spec only defines how to start an outbound connection.
You can make an application that would both initiate and accept WebSockets connections, but browsers do not do this.
You might look at Pusher App which you could use to build a WebSockets application with multiple clients. The service provides up to 20 simultaneous WebSockets clients for free (you can pay for higher scaling).
Update:
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).
How can I make a browser to browser (peer to peer) connection?
Here on Stackoverflow are several topics about P2P connections in browsers:
- Will HTML5 allow web apps to make peer-to-peer HTTP connections?
- What techniques are available to do P2P in the browser?
- Does HTML5 Support Peer-to-Peer (and not just WebSockets)
- Can HTML5 Websockets connect 2 clients (browsers) directly without using a server (P2P)
- Is it possible to create peer-to-peer connections in a web browser?
- Do websockets allow for p2p (browser to browser) communication?
- HTML 5 Peer to Peer Video Possibilities?
- Is WebRTC implemented in any browsers yet?
- http://www.w3.org/TR/2008/WD-html5-20080122/#peer-to-peer
- http://www.w3.org/TR/2008/WD-html5-20080610/comms.html#peer-to-peer
- http://dev.w3.org/2011/webrtc/editor/webrtc.html#peerconnection (W3C Editor's Draft)
- http://www.whatwg.org/specs/web-apps/current-work/webrtc.html#peerconnection (Since 5th December 2011 forwarded to W3C Editor's Draft)
- http://www.w3.org/TR/2011/WD-webrtc-20111027/#peerconnection
- https://labs.ericsson.com/apis/web-real-time-communication/
- https://labs.ericsson.com/developer-community/blog/update-webkit-contributions
- http://www.webrtc.org/
- http://www.webrtc.org/blog/firststeptowardchromeintegration
- http://groups.google.com/a/chromium.org/group/chromium-dev/browse_thread/thread/95bf1e2e1de852fc
- https://lists.webkit.org/pipermail/webkit-dev/2011-November/018445.html
chrome://flags
. It only only supports MediaStream
like Video and audio and can be tested with several Demos. Transferring application data like String
/ArrayBuffer
/... is not supported until now.Since 16th March 2012, the WebRTC Editor's Draft separates a "Peer-to-peer Data API" to send and receive generic application data (String
, ArrayBuffer
and Blob
). Chromium wants to implement the Data API soon (10th April 2012).
On April, 3rd, Mozilla published a first working example on WebRTC for Firefox as well.
DataChannel is planned for version 25 of Chrome, behind a flag, meanwhile it can be tested in Firefox Nightly/Aurora (12th December 2012):
- http://updates.html5rocks.com/2012/12/WebRTC-hits-Firefox-Android-and-iOS
- https://developer.mozilla.org/en-US/docs/Web/API/RTCDataChannel
WebRTC and Websockets. Is there a difference
There's two sides to WebRTC.
- JavaScript APIs (
getUserMedia
) that allow an app to access camera and microphone hardware. You can use this access to simply display the stream locally (perhaps applying effects), or send the stream over the network. You could send the data to your server, or you could use... PeerConnection
, an API that allows browsers to establish direct peer-to-peer socket connections. You can establish a connection directly to someone else's browser and exchange data directly. This is very useful for high-bandwidth data like video, where you don't want your server to have to deal with relaying large amounts of data.
So in a nutshell:
- WebSockets allow full-duplex communication between a browser and a web server.
- WebRTC's
PeerConnection
allows full-duplex communication between two browsers.
Will HTML5 allow web apps to make peer-to-peer HTTP connections?
Instead of intelligent guesses, here is an informed answer:
HTML 5 plans to allow peer to peer connections from javascript, but these connections WILL NOT BE RAW TCP.
The complete spec can be found at http://dev.w3.org/html5/websockets/
jrh
EDIT: with specific reference to peer to peer connections, check out these links:
- Regarding peer to peer connections: http://www.w3.org/TR/2008/WD-html5-20080122/#peer-to-peer
- Regarding broadcast connections to the local network: http://www.w3.org/TR/2008/WD-html5-20080122/#broadcast
- Regarding TCP connections (in the encoded protocol): http://www.w3.org/TR/2008/WD-html5-20080122/#tcp-connections
- Complete proposed spec: http://www.w3.org/TR/2008/WD-html5-20080122/#network
jrh
Browser to browser communication without a server?
Looks like there may be hope on the horizon: http://www.w3.org/TR/webrtc/
Related Topics
How to Create an Auto-Complete Combobox
Why Is 'This' Undefined Inside Class Method When Using Promises
Get Visitors Language & Country Code with JavaScript (Client-Side)
Javascript: Unicode String to Hex
Why Does If("String") Evaluate "String" as True But If ("String"==True) Does Not
JavaScript Displaying a Float to 2 Decimal Places
Bootstrap: Open Another Modal in Modal
Sort an Array by the "Levenshtein Distance" with Best Performance in JavaScript
How Are JavaScript Arrays Represented in Physical Memory
Can Jquery Provide the Tag Name
Understanding JavaScript Promise Object
React Routing Works in Local MAChine But Not Heroku
Sending Binary Data in JavaScript Over Http
How to Validate Google Recaptcha V2 Using JavaScript/Jquery
How to Create a Date Object from String in JavaScript
Is There a Mechanism to Loop X Times in Es6 (Ecmascript 6) Without Mutable Variables