简体   繁体   中英

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 Websockets or WebRTC? What is best for this kind of communication? peer to peer with 4 players or over a server?

Feel free to share your thoughts, I'm pretty new to this stuff..

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM