Java reliable UDP
Asked Answered
J

5

7

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.

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?

Jaquelinejaquelyn answered 30/6, 2011 at 8:21 Comment(3)
Is the overhead of TCP too bad for your app?Epigene
@krio afaik TCP is built on top of IP not UDP. UDP, however, is also built on top of IPParavane
Recommendation questions are off-topic here.Guffaw
D
2

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.

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.


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.

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.

Doorframe answered 30/6, 2011 at 8:46 Comment(4)
Not at all. I meant to say a few milli-seconds. You can achieve sub-millisecond latency but that takes more effort and is dependant on your networks. The lowest latency using a broker I have seen is less than 10 micro-seconds but comes at a cost. ;)Doorframe
Thank's for suggestion, I'll give it a try in the evening. Can you give some link to tutorials for using it?Jaquelinejaquelyn
I have a queue(maybe one per client, reasonable?). Server pushes messages on it(them). Client gets messages from this queue and process them. When some action appears on client it pushes message on it's queue and server processes it. Am I right?Jaquelinejaquelyn
In JMS you have topics and queues. Topics are good for distributing the same information to lots of listeners (publishers and listeners can be client or server.) queues are good when you want to send a message once to one or more identical listeners (i.e. you have asingle piece of work you want done) If you want a request/response model you can have a known queue for the server and a create a temporary queue for the client. This avoids naming lots of queues/topics. You can make the broker redundant and monitor all the messages esp any unprocessed ones, via a web GUI. ;)Doorframe
R
4

These are the libraries/frameworks I know of that implement something like reliable 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 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

Disclaimer: I'm the author of JNetRobust, it's new and still in alpha.

Rojo answered 21/10, 2014 at 21:48 Comment(1)
MR UDP link: moved e.g. wiki.lac.inf.puc-rio.br/doku.php?id=mr-udpDoenitz
S
3

There is an java implementation of RUDP (Reliable UDP) protocol (RFC908, RFC1151)

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

Salesman answered 16/7, 2013 at 12:12 Comment(1)
Do not use ActiveMQ. I run a performance test of multiple JMS message buses, including JBoss, MQSeries, Weblogic, SunMQ, and ActiveMQ, and I can tell you that ActiveMQ was the worst one by far, meaning lost messages and all kinds unexplained behavior and bugs. I tested with version 5.0.Ecumenicist
D
2

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.

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.


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.

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.

Doorframe answered 30/6, 2011 at 8:46 Comment(4)
Not at all. I meant to say a few milli-seconds. You can achieve sub-millisecond latency but that takes more effort and is dependant on your networks. The lowest latency using a broker I have seen is less than 10 micro-seconds but comes at a cost. ;)Doorframe
Thank's for suggestion, I'll give it a try in the evening. Can you give some link to tutorials for using it?Jaquelinejaquelyn
I have a queue(maybe one per client, reasonable?). Server pushes messages on it(them). Client gets messages from this queue and process them. When some action appears on client it pushes message on it's queue and server processes it. Am I right?Jaquelinejaquelyn
In JMS you have topics and queues. Topics are good for distributing the same information to lots of listeners (publishers and listeners can be client or server.) queues are good when you want to send a message once to one or more identical listeners (i.e. you have asingle piece of work you want done) If you want a request/response model you can have a known queue for the server and a create a temporary queue for the client. This avoids naming lots of queues/topics. You can make the broker redundant and monitor all the messages esp any unprocessed ones, via a web GUI. ;)Doorframe
G
1

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

Gallicize answered 16/6, 2015 at 16:33 Comment(0)
P
-4

UDP is by definition not a reliable service. It does not guarantee a high quality of service. You can, however, use TCP.

Paravane answered 30/6, 2011 at 8:23 Comment(5)
I guess he asks if there are any libraries that implements a reliable protocol on top of UDP.Bantustan
TCP has Congestion Control, which might make it unuseable for some apps.Epigene
you can add reliability to udp based networking by letting the receiver send a confirm back to the original sender. I think thats what op is looking for.Vampire
@Will: If you add handshaking, it is no longer UDP.Paravane
@MikeKwan: honest question: how is it no longer UDP? Does UDP care whether or not you do handshaking?Hunyadi

© 2022 - 2024 — McMap. All rights reserved.