Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Channels move blocks of data into and out of buffers to
and from various I/O sources such as files, sockets, datagrams, and so
forth. The channel class hierarchy is rather convoluted, with multiple
interfaces and many optional operations. However, for purposes of
network programming there are only three really important channel classes, SocketChannel, ServerSocketChannel, and DatagramChannel; and for the TCP connections
we’ve talked about so far you only need the first two.
The SocketChannel class reads from and writes to TCP sockets. The data
must be encoded in ByteBuffer
objects for reading and writing. Each SocketChannel is associated with a peer
Socket object that can be used for
advanced configuration, but this requirement can be ignored for
applications where the default options are fine.