Bamboo
Bamboo

Reputation: 123

Websockets faster than WebRTC?

I'm new in the WebRTC and Websockets world. I'm interested in making an 1 vs 1 web game. The problematic is just : How to send simple variables (mainly numbers) from a client to the other client ?

I have a Node.js server with websockets (via socket.io). So, for the clients, I have two solutions :

I prefer using WebRTC because it eases the work of the server, that allow him to manage more clients. So I set up the two solutions to compare and, big surprise ! Websockets are highly faster than WebRTC !

My test is simple : just a cube rotating using Three.js, the first client make a little rotation at each frame (60 per second) and push the rotation result to the client 2. At the reception, the client 2 update the rotation and render.

With Websockets, the result is perfect but with WebRTC, the client 2 runs really slow, like 5 FPS.

Is that the problem is the way I'm doing it ? Is it normal ? I'm working on localhost, on Firefox.

Upvotes: 9

Views: 7897

Answers (1)

Svetlin Mladenov
Svetlin Mladenov

Reputation: 4427

The problem is with WebRTC. The WebRTC DataChannel implementation on Chrome (probably the same goes for firefox) is limited to around 30 kbps. I don't know the reason why? Something about not flooding the internet. There is a hack to circumvent this limitation - manually changing the "B=" filed in the SDP before setting it.

However... WebRTC is p2p UNRELIABLE communication. This means that you have to take extra care to ensuring that no messages are lost and the two players observe the same events and environment. I would go with websockets just because they are so much easier, understood and supported. If the game goes viral I would consider WebRTC as a possible optimization.

However if you are doing this game just for fun then you will learn a lot of useful stuff if you choose WebRTC.

If you want to see an example how webrtc is used in real projects take a look at: http://viblast.com/demo

NB! After the introduction of SCTP-based data channels at around the Chrome 31-32 time there is no bandwidth throttling any longer and there is a new mode of operation which allows for reliable data channels.

Upvotes: 10

Related Questions