my dog learned polymorphism*
The moose likes Sockets and Internet Protocols and the fly likes Implementing UDP client/server application with some reliablity by adding sequence number Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Implementing UDP client/server application with some reliablity by adding sequence number" Watch "Implementing UDP client/server application with some reliablity by adding sequence number" New topic
Author

Implementing UDP client/server application with some reliablity by adding sequence number

sopranos mamo
Greenhorn

Joined: Oct 26, 2012
Posts: 4
I was trying to implement a Client Server Udp socket application with some reliability by adding a sequence number to each sent byte, The sequence number shall have 2 bytes from the sent datagram packet so
Could you help me out how to implement this case!!!
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1753
    
    7

Is TCP not an option? Making UDP reliable while maintaining its benefits over TCP in terms of simplicity and real-time delivery isn't exactly trivial.


Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
sopranos mamo
Greenhorn

Joined: Oct 26, 2012
Posts: 4
Dear Jelle Klap,

Yes you are right!!! But I had to implement a lot of reliability stuffs over UDP for the sake of mini project.
So i would appreciate if you give me a hint because last time i was able to develop a client server application using UDP sockets which calculates InternetChecksum , and it was fun.

Thanks
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18529
    
  40

Jelle Klap wrote:Is TCP not an option? Making UDP reliable while maintaining its benefits over TCP in terms of simplicity and real-time delivery isn't exactly trivial.


IMO, the main advantage of putting a reliable protocol on top of UDP, is that UDP is capable of running on a multicast group. This means that you get the advantages of TCP, with the network hardware support for fan out.

This is also why many messaging systems implement a reliable multicast transport.


sopranos mamo wrote:
Yes you are right!!! But I had to implement a lot of reliability stuffs over UDP for the sake of mini project.
So i would appreciate if you give me a hint because last time i was able to develop a client server application using UDP sockets which calculates InternetChecksum , and it was fun.


First, with UDP, it is only non-reliable at the packet level -- meaning whole packets can be lost. So, this means that you only need to put a sequence number on the packet.


The two functionality that you need to implement are gap detection and gap fill. Gap detection is easy. if you get a packet whose sequence number is higher than the one you expected, then you have a gap that you need to fill. Gap fill is a bit harder, you need to have your source keep old packets, and you need your target to request retransmission to fill the gap. This means that your sender is really a service -- as it needs to service request for retransmission.

Other things to note. It is possible for UDP to transmit out of order, so a gap that is detected may fill automatically without a request. It is possible, assuming you are over multicast, for one target to get the packet, but another to lose it, so you need to write your target to toss duplicate packets.

There are likely a few other concerns, but this should be enough to get you started.

Henry



Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Implementing UDP client/server application with some reliablity by adding sequence number
 
Similar Threads
TCP & UDP client/server - need help!
Communicate 2 android in 2 emulator
chat program
A client Server application using UDP Sockets
TCP or UDP