Вопрос

I'm trying to create a simple program that uses Netty's SnappyFrameEncoder/Decoder. I created a small java application that uses LocalChannels for the server/client.

The client encodes a string using Snappy, and the server decodes the string and writes it to the console.

I keep getting a StackOverFlow exception, even when I split it up into separate Client/Server programs.

If I comment out the SnappyFramedDecoder and the SnappyFramedEncoder from the pipelines, it runs without error and outputs my test message.

I've tried very long test messages, and it still gives me a StackOverFlow exception.

Could anyone help me out? I'm new to Netty. Thank you!!

I'm using Netty 4.0.0.CR2

Here is my code:

public class LocalNettyTest {
  private static String LOCAL_ID = "localtest";
  private static String TEST_STRING = "TEST";

  public void run() throws Exception {

    final LocalAddress addr = new LocalAddress(LOCAL_ID);

    Bootstrap cb = new Bootstrap();
    ServerBootstrap sb = new ServerBootstrap();
    EventLoopGroup serverGroup = new LocalEventLoopGroup();
    EventLoopGroup clientGroup = new LocalEventLoopGroup();
    try {
      sb.group(serverGroup)
      .channel(LocalServerChannel.class)
      .handler(new ChannelInitializer<LocalServerChannel>(){
        @Override
        public void initChannel(LocalServerChannel ch) throws Exception {
          ch.pipeline().addLast(new LoggingHandler(LogLevel.INFO));
        }
      })
      .childHandler(new ChannelInitializer<LocalChannel>() {
        @Override
        public void initChannel(LocalChannel ch) throws Exception {
          ch.pipeline().addLast(new SnappyFramedDecoder());
          ch.pipeline().addLast(new StringDecoder());
          ch.pipeline().addLast(new ChannelInboundMessageHandlerAdapter<String>() {

            @Override
            public void messageReceived(ChannelHandlerContext ctx,
                String msg) throws Exception {
              System.out.println ("RECEIVED: " + msg);
            }
          });
        }
      });

      cb.group(clientGroup)
      .channel(LocalChannel.class)
      .handler(new ChannelInitializer<LocalChannel>() {
        @Override
        public void initChannel(LocalChannel ch) throws Exception {
          ch.pipeline().addLast(new StringEncoder ());
          ch.pipeline().addLast(new SnappyFramedEncoder ());
        }
      });
      // Start the server.
      sb.bind(addr).sync();

      // Start the client.
      Channel ch = cb.connect(addr).sync().channel();

      ChannelFuture lastWriteFuture = ch.write(TEST_STRING);

      // Wait until all messages are flushed before closing the channel.
      if (lastWriteFuture != null) {
        System.out.println ("Waiting");
        lastWriteFuture.awaitUninterruptibly();
      }

    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      serverGroup.shutdownGracefully();
      clientGroup.shutdownGracefully();

    }
    System.out.println ("Done");
  }

  public static void main(String[] args) throws Exception {
    new LocalNettyTest().run();
  }
}
Это было полезно?

Решение

This sounds like a bug... Could you please open an issue on our bugtracker[1] and include the stacktrace etc. Also include the Netty version you are using.

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

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top