From 9f4cdfb04fe04544c8c59d9e792079bd615db71c Mon Sep 17 00:00:00 2001 From: bunny <1319900154@qq.com> Date: Fri, 24 May 2024 09:58:29 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=96=B0=E5=A2=9E):=20:rocket:=20PipLineS?= =?UTF-8?q?erver=E7=9A=84=E9=93=BE=E5=BC=8F=E4=BC=A0=E8=BE=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/bunny/service/netty/demo5/PipLineServer.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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())); }