如何设计游戏服务器的通信通道

发布于 2024-10-07 12:59:19 字数 275 浏览 4 评论 0原文

我打算设计一个游戏服务器。我希望它可以承受非常重的负载,可重用,灵活,但易于编程,我想在这些点之间取得平衡。

我决定使用nodejs和redis,协议的数据格式是JSON,websocket

我有Web开发经验,但不知道游戏服务器开发,我注意到游戏服务器非常实时,并且消息不是对等的对等,但是pub-sub通道,

nodejs,redis,JSON是设计通信通道的不错选择,大多数浏览器支持websocket吗?

也许问题太多,唯一的问题是如何为游戏服务器设计通信通道?

I am planning to design a game server. I wish it could take a very heavy load, reusable, flexiable, but easy to programming, I want to get a balance of those points.

I decide to use nodejs and redis, the data formate of protocal is JSON, websocket

I have experience of web development, but have no idea of game server development, I notice that game server is very Real-Time, and the message is not peer to peer, but pub-sub channel,

Does nodejs, redis, JSON is a good choice for design the communicate channel, does websocket support by most browser?

Maybe there are too many questions, the only question is how to design a communicate channel for a game server?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

何止钟意 2024-10-14 12:59:19

首先,下次使用真正的 标签,这样人们就能真正找到你的问题。

关于实际问题,是的,Node.js 非常适合多人游戏,尤其是 WebSockets...但由于最近发现代理服务器配置错误的安全问题,这些游戏已经延迟了至少半年(这实际上不是问题) WebSockets,但每个人和他们的妈妈都对此感到恐慌)。

详情请参阅:
http://hacks.mozilla.org/2010/12/ websockets-disabled-in-firefox-4/
http://blog .pusherapp.com/2010/12/9/it-s-not-websockets-it-s-your-broken-proxy

与此同时...

您只剩下 Flash Sockets 作为后备,如果您想要延迟小于 100 毫秒的游戏。

另外,JSON 不是一个坏主意。发送游戏数据非常臃肿,当我使用 Node.js 创建第一个多人游戏时,我所做的是创建 BiSON。这就像 JSON 的替代品,它不支持 100% 的 JSON 功能,但它致力于编码数据的小尺寸和速度。

因此,如果您愿意尝试使用 WebSockets 或在不久的将来使用 Flash 套接字,那么您应该查看我制作的两个游戏:

https://github.com/BonsaiDen/NodeGame-Orbit(策略游戏 á la Eufloria)
https://github.com/BonsaiDen/NodeGame-Shooter(小行星/几何战争多重交叉)

但请记住,根据游戏的类型,您需要的不仅仅是发送消息,特别是如果您想要延迟补偿等。

First off, next time use the real Tag, so people actually find your question.

Concerning the actual question, yes Node.js is great for multiplayer Games, especially with WebSockets... but those have been delayed for at least half a year due to recently discovered security problems with mis-configured proxy servers (that's actually not the fault of the WebSockets but everyone and their mom panicked about this).

For details:
http://hacks.mozilla.org/2010/12/websockets-disabled-in-firefox-4/
http://blog.pusherapp.com/2010/12/9/it-s-not-websockets-it-s-your-broken-proxy

In the meantime...

You're left with Flash Sockets as a fall back, if you want games with less than 100ms of lag.

Also, JSON is a bad idea. It's extremely bloated for sending game data, what I did, when I created my first multiplayer game with Node.js, was creating BiSON. This acts like a drop in replacement for JSON, it does not support 100% of JSON's features but it's committed to small size of the encoded data and speed.

So if you're willing top experiment around with WebSockets or for the near future use Flash sockets, then you should check out two of the games I've made:

https://github.com/BonsaiDen/NodeGame-Orbit (Strategy Game á la Eufloria)
https://github.com/BonsaiDen/NodeGame-Shooter (Asteroids / Geometry Wars multipler cross over)

But keep in mind that depending on the kind of your game, you need more than just to send messages around, especially if you want to have lag compensation etc.

做个ˇ局外人 2024-10-14 12:59:19

对于通信渠道,我推荐 socket.io,它提供了一个类似 websockets 的 API浏览器支持的任何内容。它会退回到 Flash 套接字,然后根据需要退回到 jsonp 和长轮询。它在 Node 中得到了很好的支持,并且当用户的浏览器原生支持 Websocket 时,用户的情况会自动变得更好。

你可以在不到 100 毫秒的时间内完成 http 请求——在家里,我通常会看到 ~75 毫秒从 Google AJAX API 服务器获取 25K 的 jquery.min.js,大约 25 毫秒返回未修改的内容——但这需要仔细的工程设计当然。如果您有 keepalive 连接,那么您就没有连接设置开销(如果您使用 SSL 来保护用户凭据,则尤其重要),因此速度可能会更快。

即便如此,我还是会使用 socket.io,因为它也提供了很好的 API。

For communication channels, I would recommend socket.io, which provides a websockets-like API atop of whatever the browser supports. It falls back to Flash sockets and then to jsonp and long-polling as needed. It's well-supported in Node, and things'll just get better automatically for users as their browsers enable websockets natively.

You can do http requests in less than 100ms -- at home I routinely see ~75ms getting 25K of jquery.min.js from the Google AJAX API servers, and ~25ms to return not-modified -- but it requires careful engineering to be sure. If you have a keepalive connection then you don't have the connection setup overhead (especially important if you're doing SSL to protect user credentials), so it could get even faster.

Even so, I would use socket.io, since it provides a good API as well.

朮生 2024-10-14 12:59:19

您似乎概括得不够全面。当然有点对点的游戏协议,这完全取决于游戏的设计,无论是否使用集中式服务器。

此外,许多游戏使用二进制协议,比特流很常见以节省带宽。 JSON 与那个世界至少有几个数量级,所以也许你应该将你的范围从“游戏”限制到更有限的东西。在这里,你似乎过于笼统了。

You seem to be under-generalizing a great deal. There certainly are game protocols that are point-to-point, it all depends on the game's design, whether it uses a centralized server or not.

Also, many games use binary protocols, with bitstreams being quite common to conserve bandwidth. JSON is at least a few orders of magnitude from that world, so perhaps you should limit your scope from "games" to something more limited. Here, it seems you're over-generalizing instead.

流殇 2024-10-14 12:59:19

最终用户 PC 上的大多数浏览器都不支持 Websockets。尝试使用通过 HTTPS 的无限加载 iframe(通过 SSL 以避免愚蠢的代理在传递它之前完全加载无限加载的 iframe)来接收数据,这是广泛支持的。对于发送,请使用 AJAX 请求。

使 iframe 页面通过 http 推送行,如下所示:

<script>newData("...")</script>

如果这对您来说太慢,请使用 flash/java 小程序进行通信。

Websockets aren't supported my most browsers that are on the PCs of endusers. Try to use endlessly-loading iframes over HTTPS (over SSL to avoid stupid proxys that want to fully load the endlessly-loading iframe before passing it on) for receiving data, that's widely supported. For sending, use AJAX requests.

Make the iframe page push lines like this one over http:

<script>newData("...")</script>

If that's too slow for you, use a flash/java applet that does the communication.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文