The Java Tutorials have been written for JDK 8. Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available.
See Dev.java for updated tutorials taking advantage of the latest releases.
See Java Language Changes for a summary of updated language features in Java SE 9 and subsequent releases.
See JDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases.
Clients and servers that communicate via a reliable channel, such as a TCP socket, have a dedicated point-to-point channel between themselves, or at least the illusion of one. To communicate, they establish a connection, transmit the data, and then close the connection. All data sent over the channel is received in the same order in which it was sent. This is guaranteed by the channel.
In contrast, applications that communicate via datagrams send and receive completely independent packets of information. These clients and servers do not have and do not need a dedicated point-to-point channel. The delivery of datagrams to their destinations is not guaranteed. Nor is the order of their arrival.
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 three classes to help you write Java programs that use datagrams to send and receive packets over the network:
DatagramSocket
,
DatagramPacket
, and
MulticastSocket
An application can send and receive DatagramPacket
s through a DatagramSocket
. In addition, DatagramPacket
s can be broadcast to multiple recipients all listening to a MulticastSocket
.