Skip to content Skip to sidebar Skip to footer

Should I Use Websockets Or Webrtc For 4player Game

I am currently making a html5 game with node.js and socket.io. The basics of the game are 4 people moving around as circles trying to hit eachother... My question is should I use

Solution 1:

WebRTC can be used not only for streaming audio/video, but also for sending data. And P2P is useful when sending huge amount of data.

In your case the traffic is very small. And I see many advantages of using a server - synchronization, or in the future, features like authentication or history.

There is also the implementation part. With WebRTC you still need a signaling server. And websockets are much easier to implement, as you don't have the session negotiation part. Also the connection is faster.

Personally, in your case I would not bother with WebRTC.

Later update: There's also the problem of browser support: websockets vs WebRTC, as @Myst mentioned in the comments.

Solution 2:

Use both.

WebRTC data channels are great for sending data with the lowest possible latency between clients, since the data does not go through a server.

From the game you describe, it sounds like low latency will be critical, so I would definitely look at using data channels to update opponents' positions as quickly as possible.

At the same time, I'd send data with web sockets to the server as well, as the keeper of truth in the game, to verify that no-one is cheating.

Fours player should not be a problem. Have each client open a peer connection to all the other clients, in a "mesh".

Post a Comment for "Should I Use Websockets Or Webrtc For 4player Game"