zoukankan      html  css  js  c++  java
  • netty channelRead 未自动执行

     1 ServerBootstrap bootstrap = new ServerBootstrap();
     2         try {
     3             bootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
     4                     .childHandler(new ChannelInitializer() {
     5                         @Override
     6                         protected void initChannel(Channel ch) throws Exception {
     7                             ch.pipeline().addLast(
     8                                     new HttpServerCodec(),new HttpObjectAggregator(LOCALPORT), // 将多个消息转换为单一的一个FullHttpRequest
     9                                     new HttpRequestDecoder(),
    10                                     new ServcerHandler()    // 自己实现的Handler
    11                             );
    12                         }
    13                     }).childOption(ChannelOption.AUTO_READ, false)
    14                     .bind(LOCALPORT).sync().channel().closeFuture().sync();

    因为设置了

    childOption(ChannelOption.AUTO_READ, false)

    所以在执行完

    public void channelActive(ChannelHandlerContext ctx)

    方法后,不会自动执行

    public void channelRead(ChannelHandlerContext ctx, Object msg) 方法;

    需要在channelActive中添加这行语句才会调用channelRead方法:

    ctx.channel().read();

  • 相关阅读:
    Yarn
    easyui
    eclipse-android
    js-小技能 そうですか
    sql server 时间处理
    上传文件
    时间 & 时间戳 之间 转换
    JDIC
    Spring 定时器
    映射
  • 原文地址:https://www.cnblogs.com/chenhao0302/p/9067544.html
Copyright © 2011-2022 走看看