刚开始对这个方法不是很清楚,执行ctx.writeAndFlush()方法时,是写完后立即执行flush,还是同样会将写事件传给下一个handelr。等执行完所有的handler的write方法后再flush()。
接着跟着源码走一遍。
第一步
@Override
protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) throws Exception {
ByteBuf in = (ByteBuf) msg;
System.out.println("server received:" + in.toString(CharsetUtil.UTF_8));
//ctx.write(Unpooled.wrappedBuffer(ByteBufUtil.decodeHexDump("aa")));
//ctx.channel().write(Unpooled.wrappedBuffer(ByteBufUtil.decodeHexDump("aa")));
//执行writeAndFlush()方法
ctx.writeAndFlush(Unpooled.wrappedBuffer(B