2

My understanding of how data transfer happens in tcp/http is this:

The application layer on the server side passes some data to the tcp layer to be sent to the client. The tcp layer breaks the application data into segments and sends it further. The tcp layer on the other end will ensure that it receives and arranges all the segments in order before passing them to its application layer.

Now, in the case of non-persistent connections, the server can simply close the connection when it is done sending data. What does this mean? Does it mean the server will send a FIN segment at the end? So, the client's tcp layer will basically wait for all the segments upto the FIN segment, pass this data to the upper layers and proceed with connection termination.

In the case of persistent connections, as the connection is not closed by the server, it is said that the client cannot know when it has to finish reading the response and do the next request. And so the content-length header and chunked transfer are used.

My question is "why can't we just send a segment similar to FIN (say DONE) to indicate that the server has transmitted all the response". The client on seeing DONE can start with the next request. What was the need to include a content-length header which comes with the issue of knowing the content length in advance?

I am sure I have misunderstood or missed something here. Please correct me where I am wrong above.

Thanks for reading upto here :)

4

2 回答 2

2

想象一下如果你的 HTTP 有效负载数据包含DONE在它的中间会发生什么。

FIN另一方面,TCP数据包在FINTCP 标头的标志内标记,因此不会有错误地将某些数据包误认为数据包的危险FIN

于 2013-06-28T19:28:46.400 回答
1

因为 DONE 可能出现在响应的主体中,因为协议中没有指定转义机制。

于 2013-06-28T19:16:30.790 回答