【问题标题】:Netty 4.0 SPDY file transfer not workingNetty 4.0 SPDY 文件传输不工作
【发布时间】:2014-08-12 03:07:21
【问题描述】:

很长一段时间以来,当我尝试将 SPDY 与 netty 一起使用时,我总是遇到同样的问题。

我检查了不同的 SPDY 源来设置我的 SPDY 服务器。到目前为止,它工作正常,我的浏览器中有一个纯 html 输出。 Chrome 还会显示一个 spdy 会话。

问题

当我将 netty 4 HttpStaticFileServerHandler 示例类放到 SPDYorHTTPHandler 时,我总是遇到同样的问题。

发送 HTML 内容,但不发送文件内容。处理程序正在发送响应,以便我的客户端检索,但文件永远不会传输。

对此有什么想法吗?

ctx.write(response) 正在向客户端写入响应(响应为HttpResponse obj)。

在下一行:(raf=RandomAccessFile)

ChannelFuture sendFileFuture;
    if (useSendFile) {
        sendFileFuture = ctx.write(new DefaultFileRegion(raf.getChannel(), 0, fileLength), ctx.newProgressivePromise());
    } else {
        sendFileFuture = ctx.write(new ChunkedFile(raf, 0, fileLength, 8192), ctx.newProgressivePromise());
    }

但它永远不会被写入。该代码 100% 基于 HttpStaticFileServerHandler 示例和 netty 4 的 SPDY 示例。

我刚刚将 createHttpRequestHandlerForHttp outputSpdyServerHandler 更改为 HttpStaticFileServerHandler

这是我使用的桩线:

    ChannelPipeline pipeline = ctx.pipeline();
    pipeline.addLast("spdyFrameCodec", new SpdyFrameCodec(version));
    pipeline.addLast("spdySessionHandler", new SpdySessionHandler(version,true));
    pipeline.addLast("spdyHttpEncoder", new SpdyHttpEncoder(version));
    pipeline.addLast("spdyHttpDecoder", new SpdyHttpDecoder(version, MAX_CONTENT_LENGTH));
    pipeline.addLast("spdyStreamIdHandler", new SpdyHttpResponseStreamIdHandler());
    pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());
    pipeline.addLast("httpRequestHandler",new HttpStaticFileServerHandler());

如果您需要更多代码,请写,我会扩展帖子。

我没有收到任何错误、警告或其他信息。

ChannelProgressiveFutureListener 从未调用过 operationProgressed 函数。

谢谢渡渡鸟。

【问题讨论】:

    标签: file http netty spdy


    【解决方案1】:

    尝试使用:

    sendFileFuture = ctx.write(new HttpChunkedInput(new ChunkedFile(raf, 0, fileLength, 8192)), ctx.newProgressivePromise());
    

    【讨论】:

    • 非常感谢,这是有效的。但我不明白为什么它会起作用。为什么我需要添加一个 HttpChunkedInput?
    • 因为否则 ChunkedWriteHandler 将产生 ByteBuf 而不是 HttpContent。 Spdy 处理程序需要 HttpContent。
    猜你喜欢
    • 2015-11-15
    • 1970-01-01
    • 2015-12-01
    • 1970-01-01
    • 2012-07-17
    • 2016-03-20
    • 1970-01-01
    • 2012-04-22
    • 2013-03-13
    相关资源
    最近更新 更多