[英]StreamWriter automatically flushing buffer when given large messages
Overview 概观
I have a Client-Server whereby I have the streamWriter.WriteLine(messageToClient);
我有一个客户端服务器,其中有
streamWriter.WriteLine(messageToClient);
on the server sending large messages. 在服务器上发送大邮件。 The
streamReader.ReadLine();
streamReader.ReadLine();
on the client is reading the 2000 length messages fine. 在客户端上读取2000条长度的消息很好。
The issue here is the streamWriter.Flush()
has no affect on the larger messages, because what I am aiming for is the server to be able to switch between the buffers flushing directly (having a fluid server message output) and not (the server response would be jumbled together until it reaches the buffers limit to flush). 这里的问题是
streamWriter.Flush()
对较大的消息没有影响,因为我的目标是服务器能够在直接刷新(具有流畅的服务器消息输出)而不是(服务器刷新)缓冲区之间切换响应会混杂在一起,直到达到刷新的缓冲区限制)。
Question: I am thinking that the buffers are auto flushing because they are full? 问题:我认为缓冲区是自动刷新的,因为它们已满? Is so what is the streamWriters max buffer size?
那么streamWriters的最大缓冲区大小是多少?
I have tested using much smaller messageToClient
and the not flushing of the stream works as intended. 我已经测试过使用更小的
messageToClient
,并且不刷新流按预期工作。 Aka the server stream outputs a group of small messages at once to the client, presumably because the buffer was full. 又称服务器流一次向客户端输出一组小消息,大概是因为缓冲区已满。
Have you tried using the constructor that takes the buffer size as an argument ? 您是否尝试过使用将缓冲区大小作为参数的构造函数 ?
public StreamWriter(
Stream stream,
Encoding encoding,
int bufferSize
)
Edit : poking around in reflector it looks like the default buffer size is 1024 bytes. 编辑 :在反射器中四处寻找,默认缓冲区大小为1024字节。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.