468,491 Members | 1,991 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,491 developers. It's quick & easy.

How to make UDP reliable

72
Hi,

I have implemented client server communication, I have used UDP as transport layer protocol. I am sending a file from client to server. Each time am sending 1024bytes. At receiver side am receiving those bytes and writing to a file. But as we know that UDP is unreliable, packets may arrive out of order. So how can I make all packets in order at receiver side? Is there any way to implement it? My target is to make sending file and receiving file to be identical. Please show me the way how can i implement?

Thanks,
Manjunath
Feb 13 '08 #1
7 9611
gpraghuram
1,275 Expert 1GB
Hi,

I have implemented client server communication, I have used UDP as transport layer protocol. I am sending a file from client to server. Each time am sending 1024bytes. At receiver side am receiving those bytes and writing to a file. But as we know that UDP is unreliable, packets may arrive out of order. So how can I make all packets in order at receiver side? Is there any way to implement it? My target is to make sending file and receiving file to be identical. Please show me the way how can i implement?

Thanks,
Manjunath

What you can do is with every chunk of data you send add a chunk count to it and in the receiving end you can read the data and store it in memory for some time till u get the all the chunks.
Then you can order the chunks based on the count and flush it to the file

Raghuram
Feb 13 '08 #2
sicarie
4,677 Expert Mod 4TB
My big question is why are you trying to do this? If you want a reliable protocol, use TCP. UDP is for streaming data, TCP is where you want to make sure you have everything being sent.

Easy fix: use TCP.
Feb 13 '08 #3
manjuks
72
My big question is why are you trying to do this? If you want a reliable protocol, use TCP. UDP is for streaming data, TCP is where you want to make sure you have everything being sent.

Easy fix: use TCP.
Ok thanks, But am intrusted to implemented using UDP, Its just for my curiosity to know how can we make UDP as reliable.

Thanks,
Manju
Feb 14 '08 #4
sicarie
4,677 Expert Mod 4TB
Ok thanks, But am intrusted to implemented using UDP, Its just for my curiosity to know how can we make UDP as reliable.

Thanks,
Manju
Make it like UDP? I don't understand the question. Why would you want to turn it into something that's already out there? Why not just use what's already out there?
Feb 16 '08 #5
Ok thanks, But am intrusted to implemented using UDP, Its just for my curiosity to know how can we make UDP as reliable.

Thanks,
Manju
UDP is designed for unreliable, connection less purpose, it is not like you can not make it as reliable, when you make it completely, then it becomes TCP. And also your are violating RFC. if you are violating RFC you many live in networking world.

TCP is one the more powerfull protocol in transport, so learn it , work on it, then i think you will become more curiosity on TCP.

If you have any design/technical problem by using TCP, please tell to me, we could innovate something else....

-Regards
Arul
Feb 16 '08 #6
Hi,

I have implemented client server communication, I have used UDP as transport layer protocol. I am sending a file from client to server. Each time am sending 1024bytes. At receiver side am receiving those bytes and writing to a file. But as we know that UDP is unreliable, packets may arrive out of order. So how can I make all packets in order at receiver side? Is there any way to implement it? My target is to make sending file and receiving file to be identical. Please show me the way how can i implement?

Thanks,
Manjunath
Why not add a header for every chunk of data? Normally, network protocols that can be implemented over UDP uses sequence numbers to keep track of its order.
Feb 17 '08 #7
chump
1
There's not much point in making UDP as reliable as TCP (just use TCP). However, it is frequently desireable to use UDP and assume some lost packets but still require that packets be processed in order.

An easy way to ensure packets are receive in order is to add a sequence number to your message. If the receiver has received and processed sequence # n and gets a packet with secquence # n-1, it drops it. If the receiver receives n+1, it processes it (sends it to the application).

f it receives n+2, it sticks it in a queue and then starts an interval timer. If the timer expires without getting any other messages, it assumes n+1 never made it and processes the queued packet. If n+1 arrives, it processes it and then pulls n+2 out of the queue and processes it.

The implementation details are a little more complicated, but you get the gist.

TCP has all sorts of stuff in the protocol, including ACKs, retries, flow control, etc, that would be very difficult to (re)implement with UDP. However, you could probably devise a light-weight retry mechanism (without the rest of TCP) on UDP with not much effort if your application can't handle dropped packets. You can do this by manuall sending ACKs for each packet, but then you will need to deal with duplicate packets, more timers, etc.
Feb 17 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Buddy Ackerman | last post: by
5 posts views Thread by splodge | last post: by
4 posts views Thread by John Grant | last post: by
1 post views Thread by =?Utf-8?B?S2F1c2hhbCBNZWh0YQ==?= | last post: by
reply views Thread by theflame83 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.