HttpWebRequest的Timeout和ReadWriteTimeout-这些对基础TCP连接意味着什么? [英] HttpWebRequest's Timeout and ReadWriteTimeout -- What do these mean for the underlying TCP connection?
问题描述
我相信我了解HttpWebRequest.Timeout
和HttpWebRequest.ReadWriteTimeout
之间的实际区别.但是,我正在寻求进一步澄清这两个超时之间的区别,包括这些值相对于基础 TCP 连接/缓冲区/状态的含义适用.
I believe I understand the practical differences between HttpWebRequest.Timeout
and HttpWebRequest.ReadWriteTimeout
. However, I'm seeking further clarity on the difference between these two timeouts, including what these values mean with respect to the underlying TCP connection/buffers/state if applicable.
例如,这些超时仅在TCP连接初始化期间使用,还是仅用于监视非托管连接的托管值?
For instance, are these timeouts used only during the initialization of the TCP connection, or are these only managed values for keeping watch on the unmanaged connection?
TCP术语中的客户端-服务器方案在哪些情况下适用或不适用这些超时?
What are the client-server scenarios in TCP terms where each of these timeouts would apply or not apply?
推荐答案
This problem has been debated on another question, see Adjusting HttpWebRequest Connection Timeout in C#. The discussion made my head spin, so I'll offer my summary.
尽管,MSDN解释了 HttpWebRequest.Timeout属性适用于HttpWebRequest.GetResponse
和HttpWebRequest.GetRequestStream
调用,说明有点混乱.
Although, MSDN explains that the HttpWebRequest.Timeout Property applies to HttpWebRequest.GetResponse
and HttpWebRequest.GetRequestStream
calls, the description is a bit confusing.
吉姆·米歇尔更为有用:Timeout
涵盖了建立有效的连接.对于较大的有效负载,这并不意味着请求/答复是完整的.
Jim Mischel is more helpful: Timeout
"is the time for the server to respond to a request, not the amount of time to wait for the server to respond and send down all of the data." Thus, Timeout
covers establishing a working connection. For large payloads, this does not imply that the request/reply is complete.
ReadWriteTimeout
适用于对通过连接传输的流的读取或写入操作.例如.当您写入GetRequestStream返回的流时.连接已经建立,但是有断开的风险.例如.网络连接断开.
ReadWriteTimeout
applies to Read or Write operations to streams that transmit over the connection. E.g. when you Write to the stream returned by GetRequestStream. The connection is already established, but there is a risk that it will break. E.g. the network connection goes down.
Jim Mischel链接对设置这些超时值提供了一些非常好的建议. IE. ReadWriteTimeout
的默认值太长.
The Jim Mischel link has some very good advice on what values to set these timeout. I.e. the default for ReadWriteTimeout
is too long.
这篇关于HttpWebRequest的Timeout和ReadWriteTimeout-这些对基础TCP连接意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!