实时游戏服务器最有效的 Java 实现是什么?

发布于 2024-11-05 21:15:54 字数 289 浏览 5 评论 0原文

我正计划构建一个 Java 服务器来处理客户端之间的实时游戏通信。最好的 Java 实现类型是什么,它可以高效且有望在客户端和服务器之间高速(例如每秒 5-15 个数据包)准确地进行通信?我知道有许多类型的 Java 网络 API(即 ObjectInputStream 和 ObjectOutputStream、DatagramPacket、KyroNet 等),但我不确定对于这种情况最有效和/或最常用的实现是什么。我认为大多数实时游戏都使用 UDP 通信方法,但我了解随之而来的可靠性问题。是否存在具有某种形式的流量控制的 UDP 实现?无论如何,提前致谢!

I'm planning on building a Java server that will handle real time game communications between clients. What is the best type of Java implementation out there that could efficiently and, hopefully, accurately communicate between a client and server at high speeds (say 5-15 packets per second)? I know there are many types of Java networking APIs (ie. ObjectInputStream and ObjectOutputStream, DatagramPacket, KyroNet, etc.), but I'm not sure what is the most effective and/or commonly used implementation for such a scenario. I would assume that most real time games use UDP communication methods, but I understand the reliability issues that come with it. Are there UDP implementations that have some form of flow control? Anyway, thanks in advance!

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

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

发布评论

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

评论(2

七堇年 2024-11-12 21:15:54

需要考虑以下几点:

  • Java NIO 确实很好,并且可以处理您正在寻找的吞吐量/延迟。不要使用任何旧的网络/序列化框架和 API
  • 延迟非常重要。您基本上需要 NIO 上的最小层,允许您以最小的开销发送非常快、小的、单独的消息。
  • 根据游戏的不同,您可能需要TCP 或UDP 或两者。 游戏进行过程中并非严格必需的消息或将包含在未来更新中的消息(例如 FPS 中的位置更新)。
  • 使用 TCP 来发送重要消息,使用 UDP 来发送 用于实时游戏的 UDP。这可能比它的价值更麻烦,但如果您确实需要针对特定​​类型的通信进行优化,请注意它作为一个选项
  • 对于实时游戏,您几乎总是在进行自定义序列化(例如,仅发送增量而不是对象位置的完整更新) - 因此请确保您的框架允许这样做

鉴于此,我建议使用以下之一

  • Kryonet - 轻量级,可定制,专为此类目的而设计
  • Netty - 稍微更面向企业,但非常有能力、强大且可扩展
  • 基于 NIO 的 Roll-your-own - 棘手,但如果您想要真正细粒度的控制,这是可能的。我以前曾经这样做过,但回想起来,我可能应该选择 Kryonet 或 Netty

祝你好运!

A few things to consider:

  • Java NIO is really good, and can handle the kind of throughput/latency you are looking for. Don't use any of the older networking / serialization frameworks and APIs
  • Latency is really important. You basically want a minimal layer over NIO that allows you to send very fast, small, inidividual messages with minimal overhead.
  • Depending on the game, you may want TCP or UDP or both. Use TCP for important messages, UDP for messages that aren't strictly necessary for the game to proceed or will be subsumed by a future update (e.g. position updates in a FPS)
  • Some people implement their own TCP-like messaging protocol over UDP for real time games. This is probably more hassle than it's worth, but be aware of it as an option if you really need to optimise for a specific type of communication
  • For real time games, you are nearly always doing custom serialisation (e.g. only sending deltas rather than full updates of object positions) - so make sure your framework allows this

Given this, I'd recommend one of the following

  • Kryonet - lightwieght, customisable, designed for this kind of purpose
  • Netty - slightly more enterprise-oriented, but very capable, robust and scalable
  • Roll-your-own based on NIO - tricky but possible if you want really fine grained control. I've done this before, but in retrospect I probably should have picked Kryonet or Netty

Good luck!

眼藏柔 2024-11-12 21:15:54

立即忘记 ObjectOutputStream 和 ObjectInputStream。这些是旧标准 java 序列化的标准输出-输入机制,它很慢并且会产生膨胀的对象。一些入门资源:

Immidiately forget ObjectOutputStream and ObjectInputStream. These are the standard output-input mechanisms of the old standard java serialization, which is slow and produces bloat objects. Some resources to start with:

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