是什么
ServerSocket里的Connection
作用
读写数据
API
public interface Channel
extends AttributeMap, ChannelOutboundInvoker, java.lang.Comparable<Channel>
A nexus to a network socket or a component which is capable of I/O operations such as read, write, connect, and bind.
A channel provides a user:
the current state of the channel (e.g. is it open? is it connected?),
the configuration parameters of the channel (e.g. receive buffer size),
the I/O operations that the channel supports (e.g. read, write, connect, and bind), and
the ChannelPipeline which handles all I/O events and requests associated with the channel
复制代码
有几个channel
1.服务器端有几个channel 2个
2.客户端有几个channel 1个
kindle
父 Channel来接受来自客户端的连接,并创建 子 Channel以用于它们之间的通信;而客户端将最可能只需要一个单独的、没有父Channel 的 Channel来用于所有的网络交互。(正如同我们将要看到的,这也适用于无连接的传输协议,如UDP,因为它们并不是每个连接都需要一个单独的Channel。)
诺曼·毛瑞尔(Norman Maurer); 马文·艾伦·沃尔夫泰尔(Marvin Allen Wolfthal). Netty实战(异步图书) (Kindle 位置 3767-3773). 人民邮电出版社. Kindle 版本.
Channel
ServerChannel
异步 io
API
All I/O operations are asynchronous.
All I/O operations in Netty are asynchronous. It means any I/O calls will return immediately with no guarantee that the requested I/O operation has been completed at the end of the call. Instead, you will be returned with a ChannelFuture instance which will notify you when the requested I/O operation has succeeded, failed, or canceled.
所有的io 都是异步。
io立即返回,但不确保io请求操作已经最终完成。
那怎么知道io有没有完成呢?回调。具体是ChannelFuture。
通道配置 ChannelConfig
SocketChannelConfig
通道回调 ChannelFuture
父子通道
API
Channels are hierarchical A Channel can have a parent depending on how it was created. For instance, a SocketChannel, that was accepted by ServerSocketChannel, will return the ServerSocketChannel as its parent on parent().
The semantics of the hierarchical structure depends on the transport implementation where the Channel belongs to. For example, you could write a new Channel implementation that creates the sub-channels that share one socket connection, as BEEP and SSHdo.