Previous | Next | Trail Map | Custom Networking and Security | Table of Contents


All about Datagrams

The previous lessons on this trail provided examples and commentary about communication between two programs running over a network. While perhaps not immediately apparent, what is true about these examples is that the order that the data is sent and received over the network is critical to the success of the communication--when reading data from a URL, the data must be received in the order that it was sent otherwise you end up with a jumbled HTML file, a corrupt zip file, or some other invalid information.

The mechanism underlying the connection between both ends of the communcation link typically uses packets to send and receive data. This mechanism must guarantee the content and the order of the packets. A guarantee such as this does not come for free--it requires overhead to verify the packet contents and the order of the packets. If a packet is corrupted, missing, or even recieved twice the two ends of the communcation link must correct the problem. This costs computation time and network bandwidth.

For many applications this guarantee is critical to the success of the transfer of information from one end of the connection to the other. However, other forms of communication don't require such strict communications and in fact are hindered by them either because of the performance hit from the extra overhead, or because the perfect connection invalidates the service altogether.

Consider, for example, a clock server that sends the current time to its client when requested to do so. If the client misses a packet does it really make sense to resend the packet? No, because the time won't be correct by the time the client receives it. If the client makes two requests and receives packets from the server out of order...it doesn't really matter because the client can figure out that the packets are out of order and request another one. The "perfect channel" here is unnecessary and may even cause performance degradation.

Another example of a service that doesn't want the guarantee of a perfect channel is the ping command. The whole point of the ping command is to test the communcation between two programs over the network. In fact, ping wants to know about dropped and mangled packets to determine how good or bad the connection is. Thus a perfect channel would invalidate this service altogether.

Services that don't require or must not have a perfect channel use what are known as datagrams to communicate.

What is a Datagram?

A datagram is an independent, self-contained message sent over the network whose arrival, arrival time, and content are not guaranteed.

Writing a Datagram Client and Server

This section contains two Java programs that use datagrams to communicate. The server-side is a quote server that listens to its DatagramSocket and sends a famous quote to a a client whenever the client requests it. The client-side is a simple program that simply makes one request of the server.


Previous | Next | Trail Map | Custom Networking and Security | Table of Contents