HttpWebRequest的Timeout和ReadWriteTimeout-这些对基础TCP连接意味着什么? [英] HttpWebRequest's Timeout and ReadWriteTimeout -- What do these mean for the underlying TCP connection?

查看:385
本文介绍了HttpWebRequest的Timeout和ReadWriteTimeout-这些对基础TCP连接意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我相信我了解HttpWebRequest.TimeoutHttpWebRequest.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.GetResponseHttpWebRequest.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屋!

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