java 多人游戏的服务器架构?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/632793/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 13:08:54  来源:igfitidea点击:

Server architecture for a multiplayer game?

javaarchitecturemultiplayer

提问by Click Upvote

I'm planning to build a small multiplayer game which could be run as a java applet or a flash file in the web browser. I haven't done any server programming before, so I'm wondering what sort of server architecture i should have.

我计划构建一个小型多人游戏,该游戏可以作为 Java 小程序或 Web 浏览器中的 Flash 文件运行。我之前没有做过任何服务器编程,所以我想知道我应该拥有什么样的服务器架构。

It'll be easy for me to create perl/php files on the server, which the java/flash code contacts to update the player position/actions, etc. But I'm considering whether i should get a dedicated web host, which OS to use, which database, etc. Also, the amount of bandwidth used and scalability is a consideration.

我很容易在服务器上创建 perl/php 文件,java/flash 代码联系这些文件以更新玩家位置/动作等。但我正在考虑是否应该获得一个专用的网络主机,哪个操作系统使用哪个数据库等。此外,使用的带宽量和可扩展性也是一个考虑因素。

Another option could be using a cloud hosting system (as opposed to a dedicated server), so they would take care of adding additional machines as the game grows. As long as each server ran the core perl/php files for updating the database, it should work fine.

另一种选择可能是使用云托管系统(而不是专用服务器),因此他们会随着游戏的发展负责添加额外的机器。只要每个服务器都运行核心 perl/php 文件来更新数据库,它应该可以正常工作。

Yet another option could be using Google app engine.

另一种选择可能是使用 Google 应用引擎。

Any thoughts regarding the server architecture, OS/database choice, and whether my method of using perl/php/python scripts for server-side programing is a good one, will be appreciated!

任何有关服务器架构、操作系统/数据库选择以及我使用 perl/php/python 脚本进行服务器端编程的方法是否好的想法,都将不胜感激!

采纳答案by Uri

You need to clarify more about the game, and think more about architecture rather than specific implementation details.

你需要更多地阐明游戏,更多地考虑架构而不是具体的实现细节。

The main question is whether your game is going to be in real time, turn based, or long-delay based (e.g., email chess). Another question is whether or not you are going to be freezing the state for subsequent reloads.

主要问题是您的游戏是实时、回合制还是长延迟(例如,电子邮件国际象棋)。另一个问题是您是否要冻结状态以进行后续重新加载。

I would highly recommend figuring out in advance whether or not all players in the same game are going to be hosted on the same server (e.g., 1000 of 4 player matches compared to 4 matches of 1000 players each). If possible, go with the first and stick everyone who is in the same game under the same server. You will have a hard enough time synchronizing multiple clients to one server, rather than having multiple servers against which players are synchronized. Otherwise, the definition of consistency is problematic.

我强烈建议您提前弄清楚同一游戏中的所有玩家是否都将托管在同一服务器上(例如,4 名玩家中的 1000 场比赛与每场 1000 名玩家中的 4 场比赛相比)。如果可能,请使用第一个并将同一游戏中的每个人都放在同一服务器下。您将很难将多个客户端同步到一个服务器,而不是让多个服务器同步玩家。否则,一致性的定义是有问题的。

If possible, have each client communicate with the server and then the server distributing updates to the clients. This way you have one "official state", and can do a variety of conflict resolutions, phantoms, etc. Peer to peer gives better performance in faster games (e.g., FPSs) but introduces tons of problems.

如果可能,让每个客户端与服务器通信,然后服务器将更新分发给客户端。这样你就有了一个“官方状态”,并且可以进行各种冲突解决、幻像等。点对点在更快的游戏(例如 FPS)中提供更好的性能,但会引入大量问题。

I cannot for the life of me see any convincing reason to do this and perl or PHP. Your game is not web based, why write it in a web oriented language? Use good old J2EE for the server, and exchange data with your clients via XML and AJAX. If possible, run a real Java application on clients rather than servlets. You can then benefit from using JMS which will take a huge load off your back by abstracting a lot of the communication details for you.

我一生都看不到任何令人信服的理由来执行此操作以及 perl 或 PHP。您的游戏不是基于 Web 的,为什么要用面向 Web 的语言编写它?使用旧的 J2EE 作为服务器,并通过 XML 和 AJAX 与您的客户端交换数据。如果可能,请在客户端而不是 servlet 上运行真正的 Java 应用程序。然后,您可以从使用 JMS 中受益,它通过为您抽象出大量通信细节来减轻您的巨大负担。

回答by Sarah Mei

For your server architecture, you might have a look at Three Rings' code. They have written a number of very scalable games in Java (both client- and server-side).

对于您的服务器架构,您可能会查看三环代码。他们用 Java(客户端和服务器端)编写了许多非常可扩展的游戏。

回答by tomasb

I would also discourage from using PHP, also HTTP isnt the best idea as it is stateless and talkative. I was working for some time in company currently developing really massive multiplayer game. The back-end is plain JVM (being connected thru tomcat by multiple clients and from mobiles one per client). So I know the less data you transfer the smaller buffers you need on server -> more clients on one machine and also a bit faster responses. Also consider security, https is quite expensive, especially if you need to transfer graphics and sounds. Binnary protocol of your own with non-browser client container would do the best (good choice is switchable protocol for the development-debugging time). Maybe sounds complicated but it isn't.

@Sarah nice hint, thanks too ;)

我也不鼓励使用 PHP,HTTP 也不是最好的主意,因为它是无状态和健谈的。我在公司工作了一段时间,目前正在开发真正的大型多人游戏。后端是普通的 JVM(由多个客户端通过 tomcat 连接,每个客户端从移动设备连接)。所以我知道你传输的数据越少,你在服务器上需要的缓冲区就越小 -> 一台机器上的客户端越多,响应速度也就越快。还要考虑安全性,https 相当昂贵,特别是如果您需要传输图形和声音。您自己的带有非浏览器客户端容器的二进制协议将是最好的(好的选择是开发调试时间的可切换协议)。也许听起来很复杂,但事实并非如此。

@Sarah 很好的提示,也谢谢;)