Datagram Communication
Fast, but unreliable datagrams may be sent and received using the DatagramPacket and DatagramSocket classes.
To send a datagram, create a new DatagramPacket which takes four arguments: the data in byte array form, the length of the message, the destination host, & the destination port. Then create a new DatagramSocket with no arguments and call its send() method.
To receive a datagram, create a new DatagramPacket which takes two arguments: a data buffer in byte array form, and the length of the buffer. Then create a new DatagramSocket which will listen on a particular port given by the argument and call its receive() method.
In two of the Socket class constructors, you may optionally specify either UDP or TCP communication. TCP is the default. These constructors are deprecated as of Java 1.1.
Next... page 11-9