简体   繁体   English

我应该将websockets或webRTC用于4player游戏

[英]should I use websockets or webRTC for 4player game

I am currently making a html5 game with node.js and socket.io. 我目前正在使用node.js和socket.io制作html5游戏。 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? 我的问题是我应该使用Websockets还是WebRTC? What is best for this kind of communication? 哪种沟通最合适? peer to peer with 4 players or over a server? 与4个玩家或服务器对等?

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. WebRTC不仅可以用于流音频/视频,还可以用于发送数据。 And P2P is useful when sending huge amount of data. 当发送大量数据时,P2P很有用。

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. 使用WebRTC,您仍然需要信令服务器。 And websockets are much easier to implement, as you don't have the session negotiation part. 而且,由于没有会话协商部分,因此Websocket易于实现。 Also the connection is faster. 而且连接速度更快。

Personally, in your case I would not bother with WebRTC. 就您个人而言,我不会为WebRTC烦恼。

Later update: There's also the problem of browser support: websockets vs WebRTC , as @Myst mentioned in the comments. 以后的更新:还有浏览器支持问题: websockets vs WebRTC ,如评论中提到的@Myst。

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. WebRTC数据通道非常适合在客户端之间以最小的延迟发送数据,因为数据不会通过服务器。

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. Fours播放器应该没有问题。 Have each client open a peer connection to all the other clients, in a "mesh". 让每个客户端在“网格”中打开与所有其他客户端的对等连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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