Channel support for UDP

The DatagramChannel class provides additional support for UDP. It can support nonblocking interchanges. The DatagramChannel class is derived from the SelectableChannel class that makes multithreaded application easier. We will examine its use in Chapter 7, Network Scalability.

The DatagramSocket class binds a channel to a port. After this class is used, it is no longer used directly. Using the DatagramChannel class means, we do not have to use datagram packets directly. Instead, data is transferred using an instance of the ByteBuffer class. This class provides several convenient methods to access its data.

To demonstrate the use of the DatagramChannel class, we will develop an echo server and client application. The server ...

Get Learning Network Programming with Java now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.