Previous | Next | Trail Map | Custom Networking and Security | All about Datagrams


What is a Datagram?

Clients and servers that communicate via a perfect channel have a dedicated point-to-point channel between themselves (or at least the illusion of one). To communicate, they must first establish the connection, transmit the data, and then close down the connection. All data sent over the channel is received in the same order that it was sent. This is guaranteed by the channel. In contrast, clients and servers that communicate via datagrams send and receive completely independent packets. These clients and servers do not have a dedicated point-to-point channel. Rather the packets are sent on their way over the network on whatever route is available.

A packet sent over a perfect channel does not contain any information about its source or its destination. The channel contains that information. In contrast, a datagram packet must contain the complete address of its source or destination (depending on if the datagram is sent or received).


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

The java.net package contains two classes to help you write Java programs that use the datagram model to send and recieve packets over the network: DatagramSocket and DatagramPacket. A DatagramSocket is a communcation link used to send datagrams between applications. A DatagramPacket is a message sent between applications via a DatagramSocket.

See also

java.net.DatagramPacket
java.net.DatagramSocket


Previous | Next | Trail Map | Custom Networking and Security | All about Datagrams