Java Netty TCP消息在channelread时间歇性截断为1420字节

Java Netty TCP消息在channelread时间歇性截断为1420字节,java,tcp,netty,tcpserver,reactor-netty,Java,Tcp,Netty,Tcpserver,Reactor Netty,有人知道如何在netty服务器收到截断的消息时解决此问题吗?我试着使用原生netty和反应器netty,但我仍然遇到同样的问题。我也尝试使用不同的解码器/编码器,但没有解决我的问题。我也尝试过改变帧长配置。这种情况每500-1000个请求发生一次。如果服务器和客户端驻留在同一台机器上,则不会发生这种情况。我期望1494字节,但有时我只收到1420字节 public final class Server { public static void main(String[] args) t

有人知道如何在netty服务器收到截断的消息时解决此问题吗?我试着使用原生netty和反应器netty,但我仍然遇到同样的问题。我也尝试使用不同的解码器/编码器,但没有解决我的问题。我也尝试过改变帧长配置。这种情况每500-1000个请求发生一次。如果服务器和客户端驻留在同一台机器上,则不会发生这种情况。我期望1494字节,但有时我只收到1420字节

public final class Server {
    public  static void main(String[] args) throws Exception {
        EventLoopGroup bossGroup = new NioEventLoopGroup(1);
        EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {

            ServerBootstrap b = new ServerBootstrap();
            b.group(bossGroup,workerGroup)
                    .channel(NioServerSocketChannel.class)
                    .handler(new LoggingHandler(LogLevel.INFO))
                    .childHandler(new ServerInitializer());
            ChannelFuture f = b.bind(8888);
            f.channel().closeFuture().sync();
        } finally {
            bossGroup.shutdownGracefully();
            workerGroup.shutdownGracefully();
        }
    }
}


@Sharable
public class ServerHandler extends SimpleChannelInboundHandler<byte[]> {
    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
    }

    @Override
    public void channelRead0(ChannelHandlerContext ctx, byte[] request) throws Exception {
        ChannelFuture future = ctx.write(request);
        future.addListener(ChannelFutureListener.CLOSE);
    }

    @Override
    public void channelReadComplete(ChannelHandlerContext ctx) {
        ctx.flush();
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
        cause.printStackTrace();
        ctx.close();
    }
}

public class ServerInitializer extends ChannelInitializer<SocketChannel> {
    private static final ServerHandler SERVER_HANDLER = new ServerHandler();

    @Override
    public void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline pipeline = ch.pipeline();
        pipeline.addLast(new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
        pipeline.addLast(new ByteArrayDecoder());
        pipeline.addLast(new ByteArrayEncoder());
        pipeline.addLast(SERVER_HANDLER);
    }
}
公共最终类服务器{
公共静态void main(字符串[]args)引发异常{
EventLoopGroup bossGroup=新的NioEventLoopGroup(1);
EventLoopGroup workerGroup=新的NioEventLoopGroup();
试一试{
ServerBootstrap b=新的ServerBootstrap();
b、 组(bossGroup、workerGroup)
.channel(NioServerSocketChannel.class)
.handler(新的LoggingHandler(LogLevel.INFO))
.childHandler(新的服务器初始值设定项());
ChannelFuture f=b.bind(8888);
f、 通道().closeFuture().sync();
}最后{
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
}
}
@可分享
公共类ServerHandler扩展了SimpleChannelInboundHandler{
@凌驾
公共无效channelActive(ChannelHandlerContext ctx)引发异常{
}
@凌驾
public void channelRead0(ChannelHandlerContext ctx,字节[]请求)引发异常{
ChannelFuture=ctx.write(请求);
future.addListener(ChannelFutureListener.CLOSE);
}
@凌驾
公共无效channelReadComplete(ChannelHandlerContext ctx){
ctx.flush();
}
@凌驾
公共无效例外情况(ChannelHandlerContext ctx,可丢弃原因){
cause.printStackTrace();
ctx.close();
}
}
公共类ServerInitializer扩展了ChannelInitializer{
private static final ServerHandler SERVER_HANDLER=new ServerHandler();
@凌驾
public void initChannel(SocketChannel ch)引发异常{
ChannelPipeline=通道管道();
addLast(新的DelimiterBasedFrameDecoder(8192,Delimiters.lineDelimiter());
addLast(新的bytearraydecorder());
pipeline.addLast(新的ByteArrayEncoder());
pipeline.addLast(服务器\处理程序);
}
}

我建议在子通道上添加一个
Logginghandler
,看看字节是否已被读取但处理程序未接收到,或者它们甚至未被Netty读取。我已经这样做了,但我发现没有任何帮助。不过还是要谢谢你:)