WebSockets适用于实时多人游戏吗? [英] Are WebSockets suitable for real-time multiplayer games?

查看:183
本文介绍了WebSockets适用于实时多人游戏吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有兴趣构建一个小型的实时多人游戏,使用HTML5 / JavaScript作为客户端,也可能使用Java作为服务器软件。

I'm interested in building a small real-time multiplayer game, using HTML5/JavaScript for the client and probably Java for the server software.

我调查了WebSockets有点,但看起来我对WebSockets实际上有什么误解。我最初认为WebSockets只是JavaScript处理TCP套接字的方式,就像在Java和其他语言中使用它一样,但似乎必须进行整个握手过程,并且每次传输都包含很多HTTP开销(并且在这种情况下,优于Ajax的好处似乎并不像第一眼那样令人兴奋)?

I looked into WebSockets a bit, but it appears I had misconceptions on what WebSockets actually are. I had initially thought of WebSockets as just JavaScript's way of handling TCP sockets, just as they are used in Java and other languages, but it appears there is a whole handshaking process that must take place, and each transmission includes much HTTP overhead (and in that case, the benefits over Ajax do not seem as exciting as at a first glance)?

在相关主题上,为此目的是否有更好的WebSockets替代方案( JavaScript中的实时多人游戏?

On a related topic, are there any better alternatives to WebSockets for this purpose (real-time multiplayer games in JavaScript)?

推荐答案

WebSockets是在Web浏览器中运行的实时多人游戏的最佳解决方案。正如评论中所指出的,有一个初始握手,其中HTTP连接已升级,但一旦建立连接,WebSockets就为服务器和客户端之间的双向通信提供了最低延迟的连接机制。

WebSockets are the best solution for realtime multiplayer games running in a web browser. As pointed out in the comments there is an initial handshake where the HTTP connection is upgraded but once the connection is established WebSockets offer the lowest latency connection mechanism for bi-directional communication between a server and a client.

我建议你看一下: https://www.youtube .com / watch?v = _t28OPQlZK4& feature = youtu.be

看看:

  • http://browserquest.mozilla.org/ code available here: https://github.com/mozilla/BrowserQuest
  • https://chrome.com/supersyncsports/

唯一的原始TCP解决方案是使用支持某种TCPClient对象的插件。我建议你试试WebSockets。

The only raw TCP solution would be to use a plugin which supports some kind of TCPClient object. I'd recommend you try out WebSockets.

你可以找到很多选项此处。只需在页面中搜索WebSockets。

You can find a number of options here. Just search for WebSockets within the page.

另请参阅 WebRTC 。根据游戏的目的以及是否需要服务器来管理游戏状态,您可以使用此技术进行点对点通信。你可能仍然需要一个解决方案来处理将玩家分组 - 在这种情况下,WebSockets是最快/最好的解决方案。

Also take a look at WebRTC. Depending on the purpose of your game and whether you need your server to manage game state, you could use this technology for peer-to-peer communication. You may still need a solution to handle putting players into groups - in that case WebSockets is the fastest/best solution.

这篇关于WebSockets适用于实时多人游戏吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆