Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do websockets allow for p2p (browser to browser) communication?

To clarify when I ask about browser to browser communication I mean without a server in between forwarding message. I would like to implement something like this for a game. If p2p in websockets isn't possible are there similar alternatives? Any help is appreciated.

like image 913
Xavier Avatar asked Nov 07 '10 15:11

Xavier


People also ask

Is WebSocket p2p?

The idea for WebSockets was born out of the limitations of HTTP-based technology. It is a peer-to-peer protocol - data that is sent from the server to the client must first be requested. In turn, WebSockets allow you to send data based on UDP-like WebSockets messages, but with higher TCP reliability.

How do WebSockets communicate?

In order to communicate using the WebSocket protocol, you need to create a WebSocket object; this will automatically attempt to open the connection to the server. The URL to which to connect; this should be the URL to which the WebSocket server will respond.

How does the browser initiate a WebSocket connection?

The client establishes a WebSocket connection through a process known as the WebSocket handshake. This process starts with the client sending a regular HTTP request to the server. An Upgrade header is included in this request which informs the server that the client wishes to establish a WebSocket connection.

Does WebRTC use WebSockets?

WebRTC doesn't use WebSockets. It has its own set of protocols including SRTP, TURN, STUN, DTLS, SCTP, … The thing is that WebRTC has no signaling of its own and this is necessary in order to open a WebRTC peer connection. This is achieved by using other transport protocols such as HTTPS or secure WebSockets.


1 Answers

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).

like image 131
kanaka Avatar answered Sep 28 '22 04:09

kanaka