我在netty中添加了两个业务类,只执行了前面一个,后面的不执行,谁放在前面就执行谁,不知道怎么设置,代码如下:
EventLoopGroup bossGroup = new NioEventLoopGroup();
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.option(ChannelOption.SO_BACKLOG, 1024)
//通过NoDelay禁用Nagle,使消息立即发出去,不用等待到一定的数据量才发出去
.option(ChannelOption.TCP_NODELAY, true)
.childHandler(new ChildChannelHandler());
ChannelFuture f = b.bind(port).sync();
if(f.isSuccess()){System.out.println("服务端启动成功");}
f.channel().closeFuture().sync();
} catch (InterruptedException e) {
} finally {
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
}
private class ChildChannelHandler extends ChannelInitializer<SocketChannel> {
protected void initChannel(SocketChannel arg0) throws Exception {
arg0.pipeline().addLast(new MyHandler());
arg0.pipeline().addLast(new MySend());
}