从IHttpHandler的无缓冲输出 [英] Unbuffered output from IHTTPHandler

查看:138
本文介绍了从IHttpHandler的无缓冲输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从的IHttpHandler 类流数据。我从数据库加载大量的行,序列化和COM pressing他们,然后把他们沿着电线。在另一端,我希望我的客户能够DECOM preSS和反序列化数据的服务器甚至做所有序列化对象之前。

I want to stream data from an IHttpHandler class. I'm loading a large number of rows from the DB, serializing, and compressing them, then sending them down the wire. On the other end, I want my client to be able decompress, and deserialize the data before the server is even done serializing all the objects.

我用 context.Response.OutputSteam.Write 来写我的数据,但它仍然看起来输出数据被放入缓冲区发送到前客户端。是否有办法避免这种缓冲?

I'm using context.Response.OutputSteam.Write to write my data, but it still seems like the output data is being put into a buffer before being sent to the client. Is there a way to avoid this buffering?

推荐答案

Response.Flush 方法应该下来送丝;但是,也有一些例外。如果IIS使用动态的COM pression,那就是它的配置为COM preSS动态内容,那么IIS不会刷新流。再有就是整个分块传输编码。如果没有指定内容长度则recieving端不知道有多大的反应身体会。这是通过分块的传输编码。某些HTTP服务器要求客户端使用接受编码请求包含分块的关键字头。其他人只是默认,当你开始指定的全长之前写字节分块;然而,他们不这样做,如果你指定你自己的传输编码响应头。

The Response.Flush method should send it down the wire; however, there are some exceptions. If IIS is using Dynamic Compression, that is it's configured to compress dynamic content, then IIS will not flush the stream. Then there is the whole 'chunked' transfer encoding. If you have not specified Content-Length then the recieving end does not know how large the response body will be. This is accomplished with the chunked transfer encoding. Some HTTP servers require that the client uses an Accept-Encoding request header containing the chunked keyword. Others just default to chunked when you begin writing bytes before the full length is specified; however, they do not do this if you have specified your own Transfer-Encoding response header.

使用IIS 7和COM pression禁用, Response.Flush 则应该始终做的伎俩,对吧?不是真的。 IIS 7可以具有拦截并请求和响应交互的多个模块。我不知道是否有安装/默认启用的,但你仍然应该意识到,他们可以影响你想要的结果。

With IIS 7 and compression disabled, Response.Flush should then always do the trick, right? Not really. IIS 7 can have many modules that intercept and interact with the request and response. I don't know if any that are installed/enabled by default, but you should still be aware that they can effect your desired result.

...我是从数据库加载大量的行,序列化,和 COM pressing 他们,然后把他们沿着电线。 ..

... I'm loading a large number of rows from the DB, serializing, and compressing them, then sending them down the wire...

好奇,你是COM pressing此内容。如果您使用的是GZIP,那么你将不会在何时以及有多少数据是通过调用flush发送的控制权。另外使用GZIP内容意味着接收端也无法启动读取数据的时候了。

Curious that you are compressing this content. If you are using GZIP then you will not be in control of when and how much data is sent by calling flush. Additionally using GZIP content means that the receiving end may also be unable to start reading data right away.

您可能想记录打入的10,50,或100行更小,易消化的卡盘。 COM preSS的发送,然后工作,对下一组行。当然,现在你需要写的东西给客户,让他们知道每个COM pressed有多大组行是,当他们走到了尽头。看到 http://en.wikipedia.org/wiki/Chunked_transfer_encoding 为如何分块的例子转移工作。

You may want to break the records into smaller, digestible chucks of 10, 50, or 100 rows. Compress that and send it, then work on the next set of rows. Of course now you will need to write something to the client so they know how big each compressed set of rows is, and when they have reached the end. see http://en.wikipedia.org/wiki/Chunked_transfer_encoding for an example of how the chunked transfer works.

这篇关于从IHttpHandler的无缓冲输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆