相关疑难解决方法(0)

netty 4.x中ServerBootstrap.option()和ServerBootstrap.childOption()之间有什么区别

根据4.0中的文档New和值得注意的,netty4提供了一个新的bootstrap API,doc提供了以下代码示例:

public static void main(String[] args) throws Exception {
    // Configure the server.
    EventLoopGroup bossGroup = new NioEventLoopGroup();
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup)
         .channel(NioServerSocketChannel.class)
         .option(ChannelOption.SO_BACKLOG, 100)
         .localAddress(8080)
         .childOption(ChannelOption.TCP_NODELAY, true)
         .childHandler(new ChannelInitializer<SocketChannel>() {
             @Override
             public void initChannel(SocketChannel ch) throws Exception {
                 ch.pipeline().addLast(handler1, handler2, ...);
             }
         });

        // Start the server.
        ChannelFuture f = b.bind().sync();

        // Wait until the server socket is closed.
        f.channel().closeFuture().sync();
    } finally {
        // …
Run Code Online (Sandbox Code Playgroud)

java netty

8
推荐指数
1
解决办法
2689
查看次数

标签 统计

java ×1

netty ×1