diff --git a/netty/service/src/main/java/cn/bunny/service/netty/demo5/PipLineServer.java b/netty/service/src/main/java/cn/bunny/service/netty/demo5/PipLineServer.java index 2e9bf15..fd278f1 100644 --- a/netty/service/src/main/java/cn/bunny/service/netty/demo5/PipLineServer.java +++ b/netty/service/src/main/java/cn/bunny/service/netty/demo5/PipLineServer.java @@ -1,12 +1,15 @@ package cn.bunny.service.netty.demo5; import io.netty.bootstrap.ServerBootstrap; +import io.netty.buffer.ByteBuf; import io.netty.channel.*; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; import lombok.extern.slf4j.Slf4j; +import java.nio.charset.Charset; + @Slf4j public class PipLineServer { public static void main(String[] args) { @@ -22,7 +25,9 @@ public class PipLineServer { pipeline.addLast("h1", new ChannelInboundHandlerAdapter() { public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { log.info("第一个"); - super.channelRead(ctx, msg); + ByteBuf buf = (ByteBuf) msg; + String name = buf.toString(Charset.defaultCharset()); + super.channelRead(ctx, name); } }); @@ -38,7 +43,7 @@ public class PipLineServer { pipeline.addLast("h3", new ChannelInboundHandlerAdapter() { @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { - log.info("第三个"); + log.info("第三个 是否拿到上一个参数:{}", msg); super.channelRead(ctx, msg); nioSocketChannel.writeAndFlush(ctx.alloc().buffer().writeBytes("服务".getBytes())); }