Java 可靠的 UDP

Java reliable UDP(Java 可靠的 UDP)

本文介绍了Java 可靠的 UDP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请推荐实现可靠 udp 的 java 库.它将用于游戏服务器与客户端和其他服务器进行通信.

PS也许您可以建议使用更高效的技术来完成此类任务(游戏服务器)?但这必须在 linux 上工作.

Please suggest java library, that implements reliable udp. It will be used for a game server to communicate to clients and to other servers.

PS Maybe you can suggest tech that will be more productive to work with for such task(game server)? But this must work on linux.

这是一款动作类游戏,因此需要尽快与服务器对话.

It's an action type game, so it needs to talk to server as fast as possible.

编辑 2: 我找到了用于 FPS 游戏的 Enet,但它是C++,如果我一秒钟调用多次会不会有开销?

Edit 2: I found Enet which was used for a FPS game, but it's C++, will there be an overhead if I call it many times a second?

推荐答案

您可能会发现您不需要所有消息类型的可靠消息传递.例如,如果您重复发送诸如播放器之类的东西的状态,并且丢失了一些数据包,则可能无关紧要.

You may find you don't need reliable messaging for all message types. For example, if you are repeatedly sending the status of things like players, and a few packets are lost it may not even matter.

有可靠的高性能基于 UDP 的库支持 Java.其中之一是 29West 的 LBM.它并不便宜,因为很难做到这一点.即使使用专业产品,您也可能需要一个专用的 UDP 网络以最大程度地减少损失.

There are reliable high performance UDP based libraries which support Java. One of these is 29West's LBM. It is not cheaper because it is very hard to get this right. Even with a professional product you may need a dedicated network for UDP to minimize loss.

出于游戏的目的,我建议您使用像 ActiveMQ 这样的 JMS 服务,该服务在您可以运行 Java 的任何地方运行.您应该能够以几毫秒的延迟每秒发送 10K 条消息.

For the purpose of a game I suggest you use a JMS service like ActiveMQ which runs wherever you can run Java. You should be able send 10K messages per second with a few milli-seconds latency.

当人们说某事必须尽可能快时,这可能意味着任何事情.对于某些人来说,这意味着 10 ms、1 ms、100 us、10 us、1 us 是可以接受的.一些网络路由器支持以 600 ns 延迟传递数据包.延迟越低,成本就越高,对设计的影响就越大.假设您需要比您需要的更快的速度可能会不必要地影响设计和成本.

When people say something must be as fast as possible, this can mean just about anything. For some people this means 10 ms, 1 ms, 100 us, 10 us, 1 us is acceptable. Some network routers support passing packets with a 600 ns latency. The lower the latency the greater the cost and the greater the impact on the design. Assuming you need more speed than you need can impact the design and cost unnecessarily.

看到你有一个人机界面,你必须现实一点.人类的反应速度不能超过大约 1/20 秒或大约 50 毫秒.如果您将消息传递控制在 5 毫秒以下,人类将无法分辨.

You have to be realistic seeing that you have a human interface. A human cannot respond faster than about 1/20 of a second or about 50 ms. If you keep the messaging to less than 5 ms, a human will not be able to tell the difference.

这篇关于Java 可靠的 UDP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Java 可靠的 UDP

基础教程推荐