netty之Channel详解
先祭出netty的架构概况图
BIO传统的做法是,InputStream和OutputStream接口,一个字节一个字节的读取传输,读取完毕关闭连接。NIO跟BIO最大的区别是,NIO有管道(channel)的概念,开启一个管道,传送一批数据,管道里面的Selector充当列车的角色,这个列车来回传输数据。
我们先看一个接口Channel。
/**
* A nexus for I/O operations.
*
* <p> A channel represents an open connection to an entity such as a hardware
* device, a file, a network socket, or a program component that is capable of
* performing one or more distinct I/O operations, for example reading or
* writing.
*
* <p> A channel is either open or closed. A channel is open upon creation,
* and once closed it remains closed. Once a channel is closed, any attempt to
* invoke an I/O operation upon it will cause a {@li