使用WebSockets进行多人HTML5游戏开发。选择什么,Node.js,或Ratchet,还是其他?

时间:2021-04-19 19:00:01

I made some research before asking this question but I couldn't find a concrete answer for my situation. I'm still new to WebSockets and games development, so I may not be able to explain some parts very well and if that's the case please tell me so I can try to explain it better.

在提出这个问题之前,我做了一些研究,但我无法找到适合我情况的具体答案。我还是WebSockets和游戏开发的新手,所以我可能无法很好地解释某些部分,如果是这种情况,请告诉我,以便我可以尝试更好地解释它。

I'm currently developing a Web application using CakePHP, which will provide several kinds of HTML5 multiplayer games. On some situations those games will need to send data to a database. The problem is, I want to use Node.js to implement the game server side logic, but I'm not sure if I'll be able to pass data to the database. I think the best approach would be sending the data from Node.js to a PHP action that will then store it on the database, but I also don't know if that will be possible.

我目前正在使用CakePHP开发一个Web应用程序,它将提供几种HTML5多人游戏。在某些情况下,这些游戏需要将数据发送到数据库。问题是,我想使用Node.js来实现游戏服务器端逻辑,但我不确定我是否能够将数据传递到数据库。我认为最好的方法是将Node.js中的数据发送到PHP操作,然后将其存储在数据库中,但我也不知道这是否可行。

I found something about this DNode thing, but I'm not sure if this is the answer for my problem and besides that it seems to be in beta version, what I would like to avoid.

我发现了一些关于这个DNode的东西,但我不确定这是否是我的问题的答案,而且它似乎是测试版,我想避免。

As an alternative, I thought about using Ratchet to implement the games server side logic. At least I know that I would be able to make it communicate with my application, but since I can't find any reference to it on games development I'm not sure if it's a good idea.

作为替代方案,我考虑使用Ratchet来实现游戏服务器端逻辑。至少我知道我能够与我的应用程序进行通信,但由于我在游戏开发中找不到任何参考,我不确定这是不是一个好主意。

I don't know about any other frameworks, so if I have better options than those two, please tell me :)

我不知道任何其他框架,所以如果我有比这两个更好的选择,请告诉我:)

Please give me your opinions. Thank you!

请告诉我你的意见。谢谢!

2 个解决方案

#1


6  

I faced a similar problem a year ago trying to develop an online multiplayer game. I ended up using Node.js for the server and Socket.io for the Websockets

一年前我遇到了类似的问题,试图开发一款在线多人游戏。我最终使用Node.js作为服务器,使用Socket.io作为Websockets

If you're new to Node.js I recommend you to read first this brief and good basic tutorial:

如果您是Node.js的新手,我建议您先阅读这篇简短而基本的教程:

http://www.nodebeginner.org/

I use node.js everyday and I really find it very useful and productive. Once you're done reading the basics read this nice tutorial of developing multiplayer html5 games with node and sockets: http://smus.com/multiplayer-html5-games-with-node/

我每天都使用node.js,我发现它非常有用和高效。阅读完基础知识后,请阅读使用节点和套接字开发多人html5游戏的精彩教程:http://smus.com/multiplayer-html5-games-with-node/

There is a link to an open source game at the end that might be helpful to you.

最后有一个开源游戏链接可能对您有所帮助。

And you can check the socket.io docs here: http://socket.io/

你可以在这里查看socket.io文档:http://socket.io/

Hope it helps so you can get started. That's the hardest part.

希望它有所帮助,因此您可以开始使用。这是最难的部分。

#2


0  

Have you considered Node.js + Lightstreamer instead of socket.io? Simone F*o recently issued an apple-to-apple data broadcasting comparison with socket.io (messages generated on the server side and sent to over 4 thousand clients, ran over two Amazon EC2 Machines) and it proved to be able to scale better than plain websockets with socket.io in CPU usage, data latency, and bandwidth consumption, with some other useful features to improve the overall performance.

您是否考虑过Node.js + Lightstreamer而不是socket.io? Simone F*o最近发布了与socket.io进行苹果到苹果的数据广播比较(在服务器端生成的消息,并发送给超过4,000个客户端,运行在两台Amazon EC2机器上),事实证明它能够比平原更好地扩展带有socket.io的websockets,CPU使用率,数据延迟和带宽消耗,还有一些其他有用的功能可以提高整体性能。

Specifically, Lightstreamer can be used with great benefits for any multiplayer games: see also this article (Optimizing Multiplayer 3D Game Synchronization Over the Web). You can walk through an online demo of a simple multiplayer 3D world in which Lightstreamer has been integrated for real-time synchronization. The demo allows you to tweak each parameter of the scenario and simulate any flavor of data delivery, while checking the actual bandwidth consumption.

具体来说,Lightstreamer可用于任何多人游戏,具有很大的优势:另见本文(通过Web优化多人3D游戏同步)。您可以浏览一个简单的多人3D世界的在线演示,其中集成了Lightstreamer以实现实时同步。该演示允许您调整场景的每个参数并模拟任何数据传输风格,同时检查实际带宽消耗。

Full source code both of the benchmarking kit and the demo are available for free on GitHub.

GitHub上免费提供基准测试工具包和演示的完整源代码。

[full disclosure: I work for Lightstreamer]

[完全披露:我为Lightstreamer工作]

#1


6  

I faced a similar problem a year ago trying to develop an online multiplayer game. I ended up using Node.js for the server and Socket.io for the Websockets

一年前我遇到了类似的问题,试图开发一款在线多人游戏。我最终使用Node.js作为服务器,使用Socket.io作为Websockets

If you're new to Node.js I recommend you to read first this brief and good basic tutorial:

如果您是Node.js的新手,我建议您先阅读这篇简短而基本的教程:

http://www.nodebeginner.org/

I use node.js everyday and I really find it very useful and productive. Once you're done reading the basics read this nice tutorial of developing multiplayer html5 games with node and sockets: http://smus.com/multiplayer-html5-games-with-node/

我每天都使用node.js,我发现它非常有用和高效。阅读完基础知识后,请阅读使用节点和套接字开发多人html5游戏的精彩教程:http://smus.com/multiplayer-html5-games-with-node/

There is a link to an open source game at the end that might be helpful to you.

最后有一个开源游戏链接可能对您有所帮助。

And you can check the socket.io docs here: http://socket.io/

你可以在这里查看socket.io文档:http://socket.io/

Hope it helps so you can get started. That's the hardest part.

希望它有所帮助,因此您可以开始使用。这是最难的部分。

#2


0  

Have you considered Node.js + Lightstreamer instead of socket.io? Simone F*o recently issued an apple-to-apple data broadcasting comparison with socket.io (messages generated on the server side and sent to over 4 thousand clients, ran over two Amazon EC2 Machines) and it proved to be able to scale better than plain websockets with socket.io in CPU usage, data latency, and bandwidth consumption, with some other useful features to improve the overall performance.

您是否考虑过Node.js + Lightstreamer而不是socket.io? Simone F*o最近发布了与socket.io进行苹果到苹果的数据广播比较(在服务器端生成的消息,并发送给超过4,000个客户端,运行在两台Amazon EC2机器上),事实证明它能够比平原更好地扩展带有socket.io的websockets,CPU使用率,数据延迟和带宽消耗,还有一些其他有用的功能可以提高整体性能。

Specifically, Lightstreamer can be used with great benefits for any multiplayer games: see also this article (Optimizing Multiplayer 3D Game Synchronization Over the Web). You can walk through an online demo of a simple multiplayer 3D world in which Lightstreamer has been integrated for real-time synchronization. The demo allows you to tweak each parameter of the scenario and simulate any flavor of data delivery, while checking the actual bandwidth consumption.

具体来说,Lightstreamer可用于任何多人游戏,具有很大的优势:另见本文(通过Web优化多人3D游戏同步)。您可以浏览一个简单的多人3D世界的在线演示,其中集成了Lightstreamer以实现实时同步。该演示允许您调整场景的每个参数并模拟任何数据传输风格,同时检查实际带宽消耗。

Full source code both of the benchmarking kit and the demo are available for free on GitHub.

GitHub上免费提供基准测试工具包和演示的完整源代码。

[full disclosure: I work for Lightstreamer]

[完全披露:我为Lightstreamer工作]