HttpWebRequest's Timeout and ReadWriteTimeout — What do these mean for the underlying TCP connection?

前端 未结 4 1033
醉酒成梦
醉酒成梦 2021-02-03 22:19

I believe I understand the practical differences between HttpWebRequest.Timeout and HttpWebRequest.ReadWriteTimeout. However, I\'m seeking further<

4条回答
  •  清歌不尽
    2021-02-03 23:01

    I believe you got the first part of your answer from @Donal Lafferty. Here's a quick summary anyway.

    HttpWebRequest.Timeout - The time before which the server has to accept the client's request. Note that this doesn't include the DNS resolution time, which is managed by the ServicePointManager.

    HttpWebRequest.ReadWriteTimeout - The time before which the client has to receive the entire body of the response from the server. Note that this timeout starts only after the server accepts the request.

    The answer to your second question is two-folded.

    1. Synchronous request:

    The TCP connections are closed on timeout, everybody's happy.

    2. Asynchronous request:

    These timeouts have absolutely no effect. If you do not have an appropriate mechanism for handing the time-outs, the TCP connections will stay open.

    That's precisely the reason why you Abort the request by registering a timeout on the AsyncWaitHandle, as shown in the example here:

    http://msdn.microsoft.com/library/21k58ta7.aspx

提交回复
热议问题