构建多人服务器的技术
我正在寻找编写自己的多人游戏服务器(最有可能在nodejs中),我想知道应该使用什么协议来传输数据?数据报是发送信息的规范吗(我意识到它们不像 HTTP 那样确认传递,可以写在协议之上)?任何经过验证的性能系统的建议都会有真正的帮助。
我想我正在寻找快速有效地处理数据传输的成功技术(维护服务器上的状态和扩展是我有充分理解的一个单独的问题)。
我希望首先支持桌面/移动游戏(MacOS、iOS 和 Android)。
I'm looking to write my own multiplayer game server (most likely in nodejs) and I was wondering what protocol I should be using to transfer data? Are Datagrams the norm to send information (i realize they don't confirm delivery like HTTP, that can written on top of the protocol)? Any suggestions of performant proven systems would be a real help.
I guess I'm looking for successful techniques in handling the data transfer quickly and effectively (maintaining state on the server and scaling are a separate issue that I have a solid understanding of).
I'm looking to initially support desktop/mobile games (MacOS, iOS, and Android).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于您的所有协议需求,请查看 socketIO。
基本上,最好的解决方案是依赖 websockets,即 TCP 套接字。 socketIO 只是一个很好的跨浏览器兼容的抽象。
您可以使用标准的长拉技术或 html5 websockets。浏览器无法访问 UDP <->服务器。
For all your protocol needs take a look at socketIO.
Basically your best solution is to rely on websockets which are TCP sockets. socketIO is just a nice cross-browser compliant abstraction.
Either you use standard long pulling techniques or html5 websockets. There is no access to UDP for browser <-> server.
Adobe 在最新版本的 Flash(Flash 10 )。它允许您进行 P2P 连接并将数据直接从客户端传输到另一个客户端,而无需经过服务器。最重要的是,它使用 UDP 来传输数据。我相信这最初是为了进行视频和音频流而设计的,但您可以使用它来传递数据。
然而,该技术的主要缺点是移动设备,因为大多数设备不支持 Flash。在这种情况下,您可以使用 Socket.IO 并将服务器用作信息路由器作为后备。
如果您想用 Javascript 构建应用程序,您仍然可以通过将功能桥接到 Javascript 来使用它。如果你想看一下桥的简单版本,你可以看看 这个 github项目(我是作者)。
There is a technology that is called RTMFP that Adobe introduced in the latest version of Flash (Flash 10). It allows you to do P2P connection and transfer data directly from a client to an other client without passing by the server. On top of that, it's using UDP to transfer data. I believe that this was originally designed to do video and audio streaming, but you can use it to pass data around.
However the main downside on this technology is the mobile since most of them don't support Flash. In this case you can use Socket.IO and use the server as a router of information as a fallback.
If you want to build your application in Javascript, you can still use it by bridging the functionnality to Javascript. If you want to take a look at a simple version of a bridge, you can take a look at this github project (I am the author).
作为一个拥有 10 年大型多人游戏 C++ 开发经验的人,我可以告诉你,大多数更高级的游戏,比如我参与过的游戏(Legends Of Kesmai、Magic: The Gathering Online、Airwarrior II、AVP、NTN Triva) )仅举几例,大多数通信都使用 TCP,因为您需要 ACK/NACK 来确保从客户端接收到数据。这并不是说 UDP 没有它的地位。在 Legends 中,我们编写了协议代码,以使用 UDP 进行超出带宽的数据传输,这并不一定要求以正确的数据包顺序接收数据并完成数据传输。当您想要在用户玩游戏时在后台更新图形文件等操作时,请使用 UDP。这种类型的传输通常用于此类目的,并允许您的 TCP 数据包按照服务器的要求到达。
As a C++ developer of Massive Multiplayer games for 10 years, I can tell you that most of your more advanced games, such as ones in which I was involved (Legends Of Kesmai, Magic: The Gathering Online, Airwarrior II, AVP, NTN Triva) to name a few, TCP is used for most communication simply because you need an ACK / NACK to be sure the data was received from the client. That is not to say UDP doesn't have it's place. In Legends we wrote the the protocol code to use UDP for out of bandwidth delivery of data which wasn't imperative that it be received in proper packet order and complete. Use UDP when you want to do things like update graphic files in the background while the user is playing, etc. This type of delivery is often used for such purposes and allows your TCP packets to arrive as required by your server.