In this chapter, we examined the use of the NIO's channel and buffer classes. A channel connects to an external source and transfers data to and from a buffer. We illustrated channel sockets, which connect to another socket across the network.
Buffers are temporary repositories for data. Using a buffer allows data to be accessed either sequentially or randomly. There are many buffer operations, which makes this a good choice for many applications.
We examined several types of channel sockets, including the SocketChannel
, ServerSocketChannel
, and AsynchronousSocketChannel
classes. The ServerSocketChannel
class supports a server and uses an accept
method to block until a client requests a connection. The method will return a SocketChannel
instance, which will be connected to the client's SocketChannel
. The AsynchronousSocketChannel
and AsynchronousSocketChannel
classes support asynchronous communication enabling non-blocking communication between two applications. The DatagramChannel...