feat(新增): 🚀 PipLineServer的链式传输
This commit is contained in:
parent
150a71a1e4
commit
9f4cdfb04f
|
@ -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()));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue