本文介绍了我应该使用websockets或webRTC进行4人游戏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用node.js和socket.io制作html5游戏。
游戏的基础是四个人四处移动,因为圈子试图互相攻击...

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

我的问题是我应该使用Websockets还是WebRTC?
这种沟通最好的是什么?与4名玩家或服务器对等?

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不仅可用于流音频/视频,还可用于发送数据。 P2P在发送大量数据时非常有用。

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.

还有实现部分。使用WebRTC,您仍然需要一个信令服务器。并且websockets更容易实现,因为您没有会话协商部分。连接也更快。

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.

就你个人而言,我不会打扰WebRTC。

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

后期更新:还存在浏览器支持问题: vs ,正如@Myst在评论中提到的那样。

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

这篇关于我应该使用websockets或webRTC进行4人游戏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 02:49