How to make UDP reliable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • manjuks
    New Member
    • Dec 2007
    • 72

    How to make UDP reliable

    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
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    Originally posted by manjuks
    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

    Comment

    • sicarie
      Recognized Expert Specialist
      • Nov 2006
      • 4677

      #3
      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.

      Comment

      • manjuks
        New Member
        • Dec 2007
        • 72

        #4
        Originally posted by sicarie
        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

        Comment

        • sicarie
          Recognized Expert Specialist
          • Nov 2006
          • 4677

          #5
          Originally posted by manjuks
          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?

          Comment

          • Arulmurugan
            New Member
            • Jan 2008
            • 90

            #6
            Originally posted by manjuks
            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

            Comment

            • mikelwagan
              New Member
              • Feb 2008
              • 6

              #7
              Originally posted by manjuks
              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.

              Comment

              • chump
                New Member
                • Feb 2008
                • 1

                #8
                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.

                Comment

                Working...