netty-channel入门.md

是什么

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.

转载于:https://juejin.im/post/5c4b7c5ff265da61590c02a5

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值