What does an P2P-API do? Surely, all you need for a P2P application/protocol is a WebSocket. If you invent a new app for P2P you'd want to tailor it to your specific need, no?
What does an P2P-API do? Surely, all you need for a P2P application/protocol is a WebSocket. If you invent a new app for P2P you'd want to tailor it to your specific need, no?
More info here:
http://peter.sh/2011/03/css-quotes-mock-ups-of-the-html5-dat...
http://src.chromium.org/viewvc/chrome?view=rev&revision=...
http://src.chromium.org/viewvc/chrome?view=rev&revision=...
http://www.whatwg.org/specs/web-apps/current-work/multipage/...
Don't be fooled by the name. Websockets are not a general socket interface in the web browser. It is simply an API and protocol for establishing a persistent, bidirectional communication channel between the browser and the server in order to better support applications like chat, notifications, live editing features, and the like, without having to resort to COMET techniques like polling, long-polling, and so on.
And that API could be extended to support p2p design patterns if browsers decided to do so.
Yes, it might be possible to extend the websocket spec to handle peer-to-peer applications. But that would be difficult, and would not fit well with the purpose it is designed for, which is creating a persistent, bidirectional communication channel between the browser and the server, securely, in such a way that it can't be used to subvert the user's browser to do malicious things.
The big issue is that when you browse to a web page, the assumption is generally that any scripts on the page should be able to communicate back to the server it came from, or possibly other servers that explicitly opt in, but not to arbitrary other machines on the internet. And even connecting back to the same server, you need to be careful not to allow the script to talk to services that don't expect a (possibly malicious) third-party script to be communicating with them from the user's machine.
The websocket API and protocol are carefully designed to prevent these sorts of problems without the user having to intervene and understand what's going on. If you tacked a peer to peer protocol on, that would add a lot of complexity (since you'd also need to add some sort of peer discovery, NAT traversal, firewall configuration, and the like), and make it even harder to guarantee these properties. Essentially, adding peer to peer support in the browser requires you to solve so many extra problems that it doesn't really make sense to think of it as an extension to websockets, but instead just do it as an entirely different standard.
You can read about it on Wikipedia: http://en.wikipedia.org/wiki/WebSockets Read the API spec: http://dev.w3.org/html5/websockets/ Read the draft protocol spec that was implemented by some browsers, but later pulled due to security concerns: http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-... And read the current working draft: http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketproto...
So it is a TCP connection. It may have its own protocol on top of TCP but as long as the browsers can create TCP connections between each other then then it can be made to work right?
The key is that websockets are limited in what they can do; the API and protocol are fundamentally designed in such a way as to make peer-to-peer communication impossible. It opens up possibilities that XMLHTTPRequest does not, but it does not allow you to do everything you could do with raw socket access.
There main reason it is impossible to do peer to peer with websockets is that you can't listen for incoming websocket connections using the websocket API; you can only initiate outbound connections, which connect to a server not written in a browser, as there are no APIs in the browser for listening for inbound connections.