简体   繁体   English

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

[英]What is the most efficient Java implementation for a real time game server?

I'm planning on building a Java server that will handle real time game communications between clients. 我正计划构建一个Java服务器来处理客户端之间的实时游戏通信。 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)? 什么是最好的Java实现类型,可以有效地,并且希望在客户端和服务器之间高速准确地进行通信(比如每秒5-15个数据包)? 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. 我知道有很多类型的Java网络API(即ObjectInputStream和ObjectOutputStream,DatagramPacket,KyroNet等),但我不确定这种情况下最有效和/或最常用的实现是什么。 I would assume that most real time games use UDP communication methods, but I understand the reliability issues that come with it. 我认为大多数实时游戏都使用UDP通信方法,但我理解随之而来的可靠性问题。 Are there UDP implementations that have some form of flow control? 是否有UDP实现具有某种形式的流量控制? Anyway, thanks in advance! 无论如何,提前谢谢!

A few things to consider: 需要考虑的一些事项:

  • Java NIO is really good , and can handle the kind of throughput/latency you are looking for. Java NIO非常好 ,可以处理您正在寻找的吞吐量/延迟。 Don't use any of the older networking / serialization frameworks and APIs 不要使用任何旧的网络/序列化框架和API
  • 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. 您基本上需要一个基于NIO的最小层,它允许您以最小的开销发送非常快速,小的,个别的消息。
  • Depending on the game, you may want TCP or UDP or both . 根据游戏的不同,您可能需要TCP或UDP或两者 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 (eg position updates in a FPS) 对于重要消息使用TCP,对于游戏继续不是严格必需的消息使用UDP,或者将其包含在将来的更新中(例如,FPS中的位置更新)
  • Some people implement their own TCP-like messaging protocol over UDP for real time games. 有些人通过UDP实现他们自己的类似TCP的消息传递协议用于实时游戏。 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 (eg 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 Kryonet - lightwieght,可定制,专为此目的而设计
  • Netty - slightly more enterprise-oriented, but very capable, robust and scalable Netty - 略微更加面向企业,但功能强大,功能强大且可扩展
  • Roll-your-own based on NIO - tricky but possible if you want really fine grained control. 基于NIO自己滚动 - 很棘手但如果你想要非常细粒度的控制可能。 I've done this before, but in retrospect I probably should have picked Kryonet or Netty 我以前做过这个,但回想起来我可能应该选择Kryonet或Netty

Good luck! 祝好运!

Immidiately forget ObjectOutputStream and ObjectInputStream. 立即忘记了ObjectOutputStream和ObjectInputStream。 These are the standard output-input mechanisms of the old standard java serialization, which is slow and produces bloat objects. 这些是旧标准java序列化的标准输出输入机制,它很慢并且会产生膨胀对象。 Some resources to start with: 一些资源开始:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM