0

私はネット初心者です。これは予想される動作ですか?

もう少し詳しく:

public class Test {
  public static void connect(){
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    Bootstrap bs = new Bootstrap();
    bs.group(workerGroup);
    bs.channel(NioSocketChannel.class);
    bs.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10000);
    bs.handler( new ChannelInitializer<SocketChannel>(){
      @Override
      protected void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline pl = ch.pipeline();
        pl.addLast("readTimeoutHandler", new ReadTimeoutHandler(1000,
          TimeUnit.MILLISECONDS));
          pl.addLast("framer", new DelimiterBasedFrameDecoder(
            16384, Delimiters.lineDelimiter()));
          pl.addLast("string-decoder", new StringDecoder());
          pl.addLast("handler", 
            new SimpleChannelInboundHandler<String> (String.class){
              @Override
              protected void channelRead0(ChannelHandlerContext ctx,
                String msg) throws Exception {
                System.out.println(msg);
              }
              @Override
              protected void exceptionCaught(ChannelHandlerContext ctx, 
                Throwable cause) throws Exception {
                if(cause instanceof ReadTimeoutException){
                  System.out.println("Timed out.");
                }
                ctx.close();
              }
          });
      }
    });
    bs.connect("127.0.0.1", 45001);
  }
}

これは単なるテストケースなので、少し間違っているかもしれませんが、パイプラインは私の実際のパイプラインに十分に似ています。

基本的に、他に何も触れずにEventLoopGroup初期化を からに変更NioEventLoopGroupOioEventLoopGroup、ブートストラップ チャネルの設定を からbootstrap.channel(NioSocketChannel.class)に変更すると、 のスローが停止します。bootstrap.channel(OioSocketChannel.class)ReadTimeoutHandlerReadTimeoutExceptions

4

1 に答える 1

0

これは Netty 4.0.4.Final で修正されました。アップグレードしてください。[1] を参照してください。

[1] https://github.com/netty/netty/issues/1614

于 2013-07-30T07:06:28.270 に答える