UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

#1 2007-11-14 02:16 PM

zhn636
Member
Registered: 2007-04-24
Posts: 146

Re: how to make UDP reliable

how many methods can we adopt to make the UDP reliable? whether we should do in the application layer .can you anyone give me some thoughts .thanks

Offline

#2 2007-11-14 02:39 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,847
Website

Re: how to make UDP reliable

My advice: don't bother...  Just use TCP...

People who try to make "reliable UDP" usually do so because they want TCP's
reliability but UDP's message/datagram-based semantics...  And, it's FAR easier to
simply overlay a message-based I/O layer on top of TCP than it is to add a reliability
layer on top of UDP...  The shit TCP has to do to be reliable is HARD WORK!  You
really don't want to have to do all of that in user-space...  You'll end up with something
that might work, but will almost certainly be less efficient than your highly-tuned over
years of real-world usage and performance gathering kernel TCP stack...  So, if you
really need hard TCP-like reliability, just use TCP; and, if you need message-based
I/O, then simply layer it on top (add a fixed-size message-length header prior to
every message sent, then your I/O functions can easily deal with individual messages)...

On the other hand, if your reliability needs are more soft, and you can tolerate some
lost messages, but want to just give some simple attempt at trying your best to get
them through whenever possible, then maybe it makes sense to use UDP with a
very minimal reliability layer stuck on top...  But, if you find yourself going too overboard
with it, you'll soon find you're on the way to reimplementing TCP in user-space (and
almost certainly very poorly, at that)...

Offline

#3 2007-11-14 02:53 PM

zhn636
Member
Registered: 2007-04-24
Posts: 146

Re: how to make UDP reliable

thanks, what methods can we adopt to make  UDP a little reliability. that is to say, how we build  minimal reliability layer stuck on top of UDP?
can you give me some advice?
thanks

Offline

#4 2007-11-14 03:03 PM

biologz
Administrator
From: Puking on the pavement
Registered: 2005-11-02
Posts: 396

Re: how to make UDP reliable

Hi zhn,

I was just wondering what exactly do you want to do? maybe it could help Rob (or anybody else) to give you more specific advices.


gethostbyintuition() is still a dream of mine

                                                 -- quoted from bash

Offline

#5 2007-11-14 03:10 PM

zhn636
Member
Registered: 2007-04-24
Posts: 146

Re: how to make UDP reliable

oh ,thanks
now I want to know to write my own method to make the UDP a little more reliable, but I do not know what method can I use. so I want someone can give me some thoughts.

Offline

#6 2007-11-14 03:19 PM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,239

Re: how to make UDP reliable

A simple way would be to number every packet, and when a receiver receives a
number that is higher than expected, it knows it missed a packet and can request
a resend. The sender can request an ACK to check if the receiver actually received
everything or not. Throw in a timeout for when the control messages are lost and
you got something what could be called reliable.

This is simple and easy to implement, the hard part is what is missing, and that is
using the network efficiently, especially under load with streamed data traffic. A
big problem is a fast sender flooding a slower receiver.

So when going for UDP, be sure it fits what you want to do. If you want
simplicity, something stateless/connectionless and prefer latency above
throughput, UDP might be a good option. If you want to do multicast, you've no
choice but to use UDP. But in most other cases you just want to use TCP.

Offline

#7 2007-11-14 03:38 PM

biologz
Administrator
From: Puking on the pavement
Registered: 2005-11-02
Posts: 396

Re: how to make UDP reliable

I just wanted to know what exactly do you want to program? just curiosity but you're not obliged to answer ;-)


gethostbyintuition() is still a dream of mine

                                                 -- quoted from bash

Offline

#8 2007-11-14 03:52 PM

zhn636
Member
Registered: 2007-04-24
Posts: 146

Re: how to make UDP reliable

oh,I am only want to write some code to make UDP a little reliable, but I do not know which layer can we add our code in the TCP/IP model  to make UDP a little reliable. whether we must  write our code in the app layer.

Offline

#9 2007-11-14 09:12 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,847
Website

Re: how to make UDP reliable

Offline

#10 2008-10-03 02:14 PM

rajeshnerella
Member
Registered: 2008-10-03
Posts: 2

Re: how to make UDP reliable

Hello,

Can anyone tell me how to make UDP reliable without using handshake process.

waiting for the replies.

thank you.

Offline

#11 2008-10-03 08:26 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,847
Website

Re: how to make UDP reliable

Did you read the previous answers above already?

You could theoretically do it without any kind of initial handshake, I suppose...  Have
the very first packet a client sends to the server specify a starting sequence# (along
with whatever real payload it's sending), and the server will need to keep a list of
known client IPs/ports it's currently dealing with, along with the current sequence# for
each one...  When it receives a packet from a previously uknown client, it adds it to
the list, initializing the sequence# to whatever one is in that client's message...  When
it receives one from a client already on the list, then it can do the sequence# checking
described by i3839 above, and request a retransfer if necessary...  Presumably, it'd
have to have some kind timeout mechanism to remove a client from the list after some
period of time without a new message arriving...  And/or a separate message (or just
a header flag or something) to tell the server to remove it...  Probably best to have a
flag in the first message sent, so if it happens to already be there, that'd force removal
first, and reinitialization with the new sequence#...

But, this is all very flaky and still not going to be totally reliable...  If that initial message
from the client goes missing enroute, the server will never know it, and the client will
only know by absense of any response (if it expects one at all)...  There's a reason
why TCP needs its 3-way handshake for reliability...  Not to mention the security
implications: UDP is trivial to forge, and a pseudo-reliability layer like this would be
simple for an attacker to subvert and be able to hijack the pseudo-connections,
injecting messages on behalf of arbitrary clients...

So, basically, I go back to what I originally said: Are you SURE you want to go down
this route?  It's probably not a wise idea, for most purposes...  You'll generally be
much better off with TCP, and an added messaging layer on top, if needed...

Offline

#12 2008-10-04 03:10 AM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,239

Re: how to make UDP reliable

The best way to have reliable UDP is to have a fibre optic cable between the two
hosts and send each packet one million times, just to be sure. The sequence
method I described doesn't use a handshake either, but is less reliable.

Offline

#13 2008-10-04 03:37 AM

rajeshnerella
Member
Registered: 2008-10-03
Posts: 2

Re: how to make UDP reliable

thank you very much for the replies..ur answers gave me a good idea.

Offline

Board footer

Powered by FluxBB