简体   繁体   English

Java 可靠 UDP

[英]Java reliable UDP

Please suggest java library, that implements reliable udp.请推荐 java 库,它实现了可靠的 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)? PS也许您可以建议使用更高效的技术来完成此类任务(游戏服务器)? But this must work on linux.但这必须适用于 linux。

Edit: It's an action type game, so it needs to talk to server as fast as possible.编辑:这是一个动作类型的游戏,所以它需要尽快与服务器对话。

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?编辑 2:我找到了用于 FPS 游戏的Enet ,但它是 C++,如果我每秒调用多次会不会有开销?

These are the libraries/frameworks I know of that implement something like reliable UDP:这些是我所知道的实现可靠 UDP 之类的库/框架:

  • Mobile Reliable UDP (MR-UDP)移动可靠 UDP (MR-UDP)

    MR-UDP aims at providing reliable communication based on UDP from/to mobile nodes (MNs), with least possible overhead. MR-UDP 旨在提供基于 UDP 与移动节点 (MN) 之间的可靠通信,并尽可能减少开销。 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 (eg Cellular to WiFi, and vice-versa).它扩展了可靠的 UDP (R-UDP)协议,具有移动性容忍功能,例如处理间歇性连接、防火墙/NAT 穿越以及对 IP 地址或网络接口(例如蜂窝到 WiFi,反之亦然)切换的鲁棒性- 反之亦然)。

  • UDT-Java UDT-Java
    Java implementation of UDP-based Data Transfer (UDT) Java 实现基于UDP 的数据传输 (UDT)

    UDT is a reliable UDP based application level data transport protocol for distributed data intensive applications over wide area high-speed networks. UDT 是一种可靠的基于 UDP 的应用级数据传输协议,适用于广域高速网络上的分布式数据密集型应用。 UDT uses UDP to transfer bulk data with its own reliability control and congestion control mechanisms. UDT 使用 UDP 传输批量数据,具有自己的可靠性控制和拥塞控制机制。 The new protocol can transfer data at a much higher speed than TCP does.新协议可以以比 TCP 高得多的速度传输数据。 UDT is also a highly configurable framework that can accommodate various congestion control algorithms. UDT 也是一个高度可配置的框架,可以适应各种拥塞控制算法。

  • JNetRobust JNet鲁棒

    Fast, reliable & non-intrusive message-oriented virtual network protocol for the JVM 1.6+.适用于 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 package 大于 UDP 的 package,但小于 TCP 的 package
    • no flow control没有流量控制
    • no congestion control没有拥塞控制

Disclaimer: I'm the author of JNetRobust, it's new and still in alpha.免责声明:我是 JNetRobust 的作者,它是新的并且仍处于 alpha 阶段。

There is an java implementation of RUDP (Reliable UDP) protocol (RFC908, RFC1151)有一个 RUDP(可靠 UDP)协议(RFC908、RFC1151)的 java 实现

http://sourceforge.net/projects/rudp/?source=dlp http://sourceforge.net/projects/rudp/?source=dlp

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.有可靠的高性能 UDP 库支持 Java。 One of these is 29West's LBM.其中之一是 29West 的 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 的专用网络,以尽量减少损失。

For the purpose of a game I suggest you use a JMS service like ActiveMQ which runs wherever you can run Java.出于游戏的目的,我建议您使用像 ActiveMQ 这样的 JMS 服务,该服务在您可以运行 Java 的任何地方运行。 You should be able send 10K messages per second with a few milli-seconds latency.您应该能够以几毫秒的延迟每秒发送 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.对于某些人来说,这意味着 10 ms、1 ms、100 us、10 us、1 us 是可以接受的。 Some network routers support passing packets with a 600 ns latency.一些网络路由器支持以 600 ns 延迟传递数据包。 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.假设您需要比您需要的更快的速度可能会不必要地影响设计和成本。

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.人类的反应速度不能超过大约 1/20 秒或大约 50 毫秒。 If you keep the messaging to less than 5 ms, a human will not be able to tell the difference.如果您将消息传递保持在 5 毫秒以下,人类将无法区分。

Libjitsi has SCTP over UDP, which breaks everything up into packets like UDP but guarantees reliable delivery, like TCP. Libjitsi 在 UDP 上有 SCTP,它将所有内容分解为 UDP 等数据包,但保证可靠交付,如 TCP。 See https://github.com/jitsi/libjitsi/blob/master/src/org/jitsi/sctp4j/Sctp.javahttps://github.com/jitsi/libjitsi/blob/master/src/org/jitsi/sctp4j/Sctp.java

UDP is by definition not a reliable service. UDP 根据定义不是可靠的服务。 It does not guarantee a high quality of service.它不能保证高质量的服务。 You can, however, use TCP .但是,您可以使用TCP

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

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