Java 可靠的 UDP
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6531956/
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
Java reliable UDP
提问by Viktor
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.
请建议实现可靠 udp 的 java 库。它将用于游戏服务器与客户端和其他服务器进行通信。
PS 也许您可以建议可以更有效地处理此类任务的技术(游戏服务器)?但这必须在 linux 上工作。
Edit:It's an action type game, so it needs to talk to server as fast as possible.
编辑:这是一个动作类型的游戏,所以它需要尽快与服务器对话。
Edit 2:I found Enetwhich was used for a FPS game, but it's C++, will there be an overhead if I call it many times a second?
编辑 2:我发现Enet用于 FPS 游戏,但它是 C++,如果我每秒调用它很多次会不会有开销?
采纳答案by Peter Lawrey
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.
您可能会发现并非所有消息类型都需要可靠的消息传递。例如,如果您重复发送诸如播放器之类的东西的状态,并且丢失了一些数据包,则甚至可能无关紧要。
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.
有可靠的基于 UDP 的库支持 Java。其中之一是 29West 的 LBM。它并不便宜,因为很难做到这一点。即使使用专业产品,您也可能需要专用的 UDP 网络以最大程度地减少损失。
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.
出于游戏的目的,我建议您使用像 ActiveMQ 这样的 JMS 服务,它可以在您可以运行 Java 的任何地方运行。您应该能够以几毫秒的延迟每秒发送 10K 条消息。
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.
当人们说某事必须尽可能快时,这可能意味着任何事情。对于某些人来说,这意味着 10 ms、1 ms、100 us、10 us、1 us 是可以接受的。一些网络路由器支持以 600 ns 延迟传递数据包。延迟越低,成本越高,对设计的影响就越大。假设您需要的速度超出您的需要,可能会不必要地影响设计和成本。
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.
你必须现实地看到你有一个人机界面。人类的反应速度不能超过约 1/20 秒或约 50 毫秒。如果您将消息传递保持在 5 毫秒以内,人们将无法分辨其中的区别。
回答by mucaho
These are the libraries/frameworks I know of that implement something like reliable UDP:
这些是我所知道的实现可靠 UDP 之类的库/框架:
MR-UDP aims at providing reliable communication based on UDP from/to mobile nodes (MNs), with least possible overhead. It extends a Reliable UDP (R-UDP)protocol with mobility-tolerating features, such as the ability to handle intermit-tent connectivity, Firewall/NAT traversal and robustness to switching of IP addresses or network interfaces (e.g. Cellular to WiFi, and vice-versa).
UDT-Java
Java implementation of UDP-based Data Transfer (UDT)UDT is a reliable UDP based application level data transport protocol for distributed data intensive applications over wide area high-speed networks. UDT uses UDP to transfer bulk data with its own reliability control and congestion control mechanisms. The new protocol can transfer data at a much higher speed than TCP does. UDT is also a highly configurable framework that can accommodate various congestion control algorithms.
Fast, reliable & non-intrusive message-oriented virtual network protocol for the JVM 1.6+.
It resides between the transport and the application layer.
Characteristics:- reliability of transmitted data
- received, unvalidated data is available immediately
- the package is bigger than UDP's package, but smaller than TCP's package
- no flow control
- no congestion control
MR-UDP 旨在提供基于 UDP 的可靠通信,从/到移动节点 (MN),开销尽可能小。它扩展了具有移动容忍特性的可靠 UDP (R-UDP)协议,例如处理间歇性连接、防火墙/NAT 穿越和 IP 地址或网络接口(例如蜂窝网络到 WiFi,副-相反)。
UDT-Java
基于UDP 的数据传输 (UDT) 的Java 实现UDT 是一种可靠的基于 UDP 的应用级数据传输协议,适用于广域高速网络上的分布式数据密集型应用。UDT 使用 UDP 传输批量数据,具有自身的可靠性控制和拥塞控制机制。新协议可以以比 TCP 高得多的速度传输数据。UDT 也是一个高度可配置的框架,可以适应各种拥塞控制算法。
适用于 JVM 1.6+ 的快速、可靠且非侵入性的面向消息的虚拟网络协议。
它位于传输层和应用层之间。
特征:- 传输数据的可靠性
- 收到,未经验证的数据立即可用
- 包比UDP的包大,但比TCP的包小
- 无流量控制
- 没有拥塞控制
Disclaimer: I'm the author of JNetRobust, it's new and still in alpha.
免责声明:我是 JNetRobust 的作者,它是新的并且仍处于 alpha 阶段。
回答by Oliver_Vienna
There is an java implementation of RUDP (Reliable UDP) protocol (RFC908, RFC1151)
有 RUDP (Reliable UDP) 协议 (RFC908, RFC1151) 的 java 实现
回答by Michael Lafayette
Libjitsi has SCTP over UDP, which breaks everything up into packets like UDP but guarantees reliable delivery, like TCP. See https://github.com/jitsi/libjitsi/blob/master/src/org/jitsi/sctp4j/Sctp.java
Libjitsi 具有基于 UDP 的 SCTP,它将所有内容分解为像 UDP 一样的数据包,但可以保证可靠的传输,例如 TCP。见https://github.com/jitsi/libjitsi/blob/master/src/org/jitsi/sctp4j/Sctp.java