在线 Flash 游戏的轮询与套接字服务器

发布于 2024-09-03 11:10:43 字数 309 浏览 5 评论 0原文

我想制作一款在线 Flash 游戏,它将具有社交功能,但游戏玩法将主要是单人游戏。例如,屏幕上不会同时出现两个玩家,社交互动将通过异步消息进行,不会有实时聊天或其他任何内容。大部分逻辑将发生在客户端中,服务器将验证客户端逻辑,但不需要完全同步,这就是为什么我认为轮询可能会令人满意。

我在很多地方读到,套接字服务器比使用轮询在线游戏更有效,但这主要是考虑到比我描述的游戏具有更多多人交互的多人游戏吗?如果许多用户同时在线玩游戏,但每个用户都玩相对独立的游戏,并且不与每个玩家实时交互,那么轮询可能没问题,或者如果您有在线游戏,则无论如何都建议使用套接字您想象有很多人同时玩的游戏吗?谢谢!

I want to make an online flash game, it will have social features but the gameplay will be primarily single-player. For example, no two players will appear on the screen at once, the social interaction will be through asynchronous messages, there won't be real-time chat or anything. Much of the logic would happen in the client, the server would validate the client logic, but it wouldn't need to be totally synchronous, which is why I'm thinking polling might be satisfactory.

I have read in many places that socket servers can be more efficient than using polling for online games, but is that mainly a consideration for games that are more multi-player with more mult-player interactions than the game I have descriebed? If many users are playing online at the same time, but each playing a relatively isolated game, and not interacting to in real-time with each players, could polling be okay, or would using sockets be advisable no matter what if you have an online game that you envision many people playing at the same time? Thanks!

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

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

发布评论

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

评论(1

ㄟ。诗瑗 2024-09-10 11:10:43

你们有什么类型的服务器?它是否支持持久连接(即它可以自行运行循环)还是仅支持无状态 模式(您的客户端必须进行轮询)?

状态

像 Quake / Half-life 等 多人游戏在与所连接的客户端保持持久连接的服务器上运行。这样效率更高,因为它可以将相关的游戏状态保存在 RAM 内存中,而不是在每条消息之后将其保存到光盘/数据库中。

无状态

如果您有一个 Web 服务器(例如 PHP),您几乎只能使用无状态模式,您只需等待客户端消息,从数据库加载所有相关信息,进行一些计算,然后将答案返回给客户端。在这种情况下,您需要为每笔“交易”(客户端民意调查)执行所有这些操作。

如果通信稀疏且简单,无状态服务器实际上可能是更好的选择。它很容易实现。

What kind of server do you have? Does it support persistent connections (i.e. can it run a loop on its own) or does it only support stateless mode (where your clients have to poll)?

Stateful

Multiplayer games like Quake / Half-life and so on are run on servers that keep persistent connections to the clients that connect. That is a lot more efficient because it can then keep the relevant game state in RAM memory instead of saving it to the disc/database after each message.

Stateless

If you have a web server (PHP for example) you are pretty much limited to stateless mode where you simply wait for a client message, load all relevant information from a database, do some calculations and then return an answer to the client. In this case you need to do all of this for each and every "transaction" (client poll).

If the communication is sparse and simple the stateless server might actually be a better choice. It is very easy to implement.

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