首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Netty与JDK版本冲突

Netty与JDK版本冲突
EN

Stack Overflow用户
提问于 2018-09-18 15:08:41
回答 1查看 346关注 0票数 0

我正在使用教程学习netty工具,但我遇到了一个问题,我认为它可能与Netty包和JDK的版本有关。现在,我的jdk是1.8,Netty版本是netty 4.0.0 Final.jar,这是我从netty官方网站下载的。

下面是错误代码,,我在错误行后面使用了注释。因为我不知道如何在代码段中突出显示,所以您可能需要仔细注意注释,幸运的是只有两行。

代码语言:javascript
运行
复制
    EventLoopGroup pGroup = new NioEventLoopGroup();    
    EventLoopGroup cGroup = new NioEventLoopGroup();    
    ServerBootstrap b = new ServerBootstrap();

    b.group(pGroup, cGroup)                             
    .channel(NioServerSocketChannel.class)              
    .option(ChannelOption.SO_BACKLOG, 1024)             
    .option(ChannelOption.SO_SNDBUF, 32*1024)           
    .option(ChannelOption.SO_RCVBUF, 32*1024)           
    .option(ChannelOption.SO_KEEPALIVE, true)           
    .childHandler(new ChannelInitializer<SocketChannel>() {        // there is an error, which indicates that the generic <SocketChannel> is not a valid substitute according the eclipse automatic prompt

        @Override
        protected void initChannel(SocketChannel sc) throws Exception {
            sc.pipeline().addLast(new ServerHandler());            // there are two errors about the pipeline method and ServerHander construtor
        }

    });

    ChannelFuture cf1 = b.bind().sync();                

    cf1.channel().closeFuture().sync();                 

    pGroup.shutdownGracefully();
    cGroup.shutdownGracefully();
EN

回答 1

Stack Overflow用户

发布于 2018-09-19 00:09:32

我怀疑你在这里输入了错误的SocketChannel。这需要是io.netty.channel.socket.SocketChannel,但您很可能使用了java.nio. SocketChannel

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52389647

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档