首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Netty ClosedChannelException

Netty ClosedChannelException
EN

Stack Overflow用户
提问于 2013-08-04 12:27:16
回答 1查看 1.5K关注 0票数 1

我对netty很陌生,我遵循这个示例使用netty编写了一个静态文件服务器。但是每当服务器提供一个大的js文件时。它会运行到ClosedChannelException。

下面是我的代码,我将chunkedFile写成http响应。当一个大的js文件被提供时,我会得到closedChannelException,并且raf文件也会关闭。

你能帮我找出我在这里做错了什么吗?此外,是否有一个简单的教程,让我了解网络控制的基本流程?

// Write the content. ChannelFuture writeFuture = null; try { long fileLength = raf.length(); HttpResponse response = new DefaultHttpResponse( HttpVersion.HTTP\_1\_1, HttpResponseStatus.OK); response.setHeader(HttpHeaders.Names.CONTENT\_LENGTH, fileLength); Channel c = ctx.getChannel();

代码语言:javascript
复制
        // Write the initial line and the header.
        c.write(response);

        writeFuture = c.write(new ChunkedFile(raf, 0, fileLength, 8192));
    }
    finally
    {
        raf.close();
        if (writeFuture != null)
            writeFuture.addListener(ChannelFutureListener.CLOSE);
    }
}

<

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-08-04 18:18:24

在finally块中调用raf.close()是错误的,因为它可能还没有编写它。实际上,netty会注意在写完之后关闭它。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18042923

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档