Netty - 不使用 channelRead 的 ByteBuf 调用 writeAndFlush 时未收到新消息

Netty - Not receiving new message when not calling writeAndFlush with ByteBuf of channelRead

提问人:owob 提问时间:9/16/2023 更新时间:9/16/2023 访问量:17

问:

当我传递给 const ProxyServerHandler 时,一切照常进行。 但是当我通过时,netty 似乎只是卡在那里,不会再被解雇了。dataactiveBufferchannelRead

    private ByteBuf activeBuffer = ByteBufAllocator.DEFAULT.buffer();
    @Override
    public void channelRead(final ChannelHandlerContext ctx, Object msg) {
        ByteBuf data = (ByteBuf) msg;
        activeBuffer.writeBytes(data);
        serverHandler = new ProxyServerHandler(this, config.getKey(), activeBuffer or data); // start connection with server.
    }

ProxyServerHandler

    ProxyServerHandler(PlayerProxyHandler proxy, IHostPort target, ByteBuf cached) {
        this.proxy = proxy;
        Bootstrap b = new Bootstrap();
        b.group(proxy.handler.channel().eventLoop())
                .channel(NioSocketChannel.class)
                .handler(this)
                .option(ChannelOption.AUTO_READ, false);

        ChannelFuture f = b.connect(target.host, target.port);
        channel = f.channel();

        f.addListener((ChannelFutureListener) future -> {
            try {
                if (future.isSuccess()) {
                    channel.writeAndFlush(cached).sync();
                    System.out.println("test"); // The test is printed normally and no error just stuck.
                } else {
                    channel.close();
                }
            } catch (Throwable e) {
                logger.log(Level.SEVERE, "", e);
            }
        });
    }

我不知道要调试。

Java 代理 IO netty

评论


答: 暂无答案