Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Netty-查找通道ID_Netty_Channel_Illegalstateexception - Fatal编程技术网

Netty-查找通道ID

Netty-查找通道ID,netty,channel,illegalstateexception,Netty,Channel,Illegalstateexception,我刚开始和内蒂一起工作。我已经有了一个服务器,我正在为客户端编写代码 在客户机中,我使用以下代码为ClientBootstrap对象设置了一个新的PipelineFactory bootstrap.setPipelineFactory(new ChannelPipelineFactory() { public ChannelPipeline getPipeline() { return Channels.pipeline

我刚开始和内蒂一起工作。我已经有了一个服务器,我正在为客户端编写代码

在客户机中,我使用以下代码为ClientBootstrap对象设置了一个新的PipelineFactory

    bootstrap.setPipelineFactory(new ChannelPipelineFactory() 
    {
        public ChannelPipeline getPipeline() 
        {
            return Channels.pipeline(new ResponseHandler());
        }
    }
                                );
其中ResponseHandler()是我扩展SimpleChannelHandler的类

我在找频道ID,我找到了

 bootstrap.getPipeline().getChannel().getId();
但它抛出IllelgalStateException并说我不能调用getPipeline(),因为我调用了setPipelineFactory()。获取频道ID的方法是什么?

您是否已呼叫connect

我认为在连接之后,您可以在使用的所有方法上获得频道ID


给内蒂4

给定ChannelHandlerContext对象(变量名=ctx),它将

ctx.channel().id()
你给connect打电话了吗

我认为在连接之后,您可以在使用的所有方法上获得频道ID


给内蒂4

给定ChannelHandlerContext对象(变量名=ctx),它将

ctx.channel().id()

@MouseEvent已修复,尽管Netty的最新稳定版本现在是4.x系列。@MouseEvent已修复,尽管Netty的最新稳定版本现在是4.x系列。