方法 职责
writeInbound(Object... msgs) 将入站消息写入到EmbeddedChannel中
readInbound() 从EmbeddedChannel中读取一个入站消息,任何返回的消息都穿过了整个ChannelPipeLine
writeOutbound(Object... msgs) 将出站消息写入到EmbeddedChannel中
readOutbound() 从EmbeddedChannel中读取一个出站消息,任何返回的消息都穿过了整个ChannelPipeLine

10.1 示例

//测试结果
Received message:0
Received Finished!
Received message:1
Received Finished!
Received message:2
Received Finished!
embeddedChannel readInbound:0
embeddedChannel readInbound:1
embeddedChannel readInbound:2
public class EmBeddedChannelTest {
public static void main(String[] args) {
ByteBuf byteBuf = Unpooled.buffer();
for (int i = 0; i < 3; i++) {
byteBuf.writeInt(i);
} EmbeddedChannel embeddedChannel = new EmbeddedChannel(); //获取channelPipeLine
ChannelPipeline channelPipeline = embeddedChannel.pipeline();
channelPipeline.addLast(new SimpleChannelInBoundHandlerTest());
channelPipeline.addFirst(new DecodeTest()); //写入测试数据
embeddedChannel.writeInbound(byteBuf); System.out.println("embeddedChannel readInbound:"+embeddedChannel.readInbound());
System.out.println("embeddedChannel readInbound:"+embeddedChannel.readInbound());
System.out.println("embeddedChannel readInbound:"+embeddedChannel.readInbound()); } } //解码器
class DecodeTest extends ByteToMessageDecoder {
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
if( in.readableBytes()>=4 ){
out.add(in.readInt());
}
}
} //channelHandler
class SimpleChannelInBoundHandlerTest extends SimpleChannelInboundHandler {
@Override
protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
System.out.println("Received message:"+msg);
System.out.println("Received Finished!");
ctx.fireChannelRead(msg);
}
}

最新文章

  1. 物联网框架SuperIO 2.2.9和ServerSuperIO 2.1同时更新,更适用于类似西门子s7-200发送多次数据,才能读取数据的情况
  2. Delphi DLL的创建、静态及动态调用
  3. HDU 1712 分组背包
  4. Lua小技巧
  5. Sum of Left Leaves
  6. FK JavaScript:ArcGIS JavaScript类库加载不成功而导致的程序异常
  7. 【HAOI2006】【BZOJ1051】【p1233】最受欢迎的牛
  8. SVN理解
  9. 【Android - 框架】之XBanner的使用
  10. 给tcpdump加点颜色看看
  11. C C++ OC iOS面试重点问题(一)
  12. centos 添加epel、remi仓库和ELRepo仓库
  13. codeforces #550E Brackets in Implications 结构体
  14. mysql c connector 多条sql语句执行示例
  15. ABP入门系列之1——ABP总体介绍
  16. uploadify上传图片的使用
  17. Linux期中架构
  18. Android dp、dip、dpi、px、sp简介及相关换算,及其应用实例
  19. &quot;Native table &#39;performance_schema&#39;.&#39;session_variables&#39; has the wrong structure&quot;) [SQL: &quot;SHOW VARIABLES LIKE &#39;sql_mode&#39;&quot;]
  20. etcd 集群运维实践

热门文章

  1. k8s基础 etcd参数
  2. 第三天的 No session 问题
  3. Struts2学习第七课 ActionSupport
  4. c++中的const关键字的理解
  5. 历届试题_log大侠
  6. 微信小程序小结(2) ------ 自定义组件
  7. Codeforces Round #523 (Div. 2)D(二分,多重集)
  8. SnapKit swift实现高度自适应的新浪微博布局
  9. P2742 【模板】二维凸包 / [USACO5.1]圈奶牛Fencing the Cows
  10. express-http-proxy 的基础使用