简体   繁体   English

HTTP与管道的持久连接。 如何将多个文件按TCP划分为段

[英]HTTP persisted connection with pipeline. How multiple files are divided in segments by TCP

I have a very simple question which answer seems impossible to find as I want it. 我有一个非常简单的问题,根据我的需要似乎找不到答案。 Let's suppose I have a tcp connection between a client and a sever and the client made a request for a page that contains 2 files. 假设我在客户端和服务器之间建立了tcp连接,并且客户端请求包含2个文件的页面。 We assume that the http connection is persisted and with pipeline so the 2 requests for the files are send in one tcp segment to the from the client to the server. 我们假定http连接是持久的,并且具有管道,因此对文件的2个请求在一个tcp段中从客户端发送到服务器。 Now suppose the files that the client wants are like 4500 bytes and 3000 bytes and the MSS of tcp is 1460 bytes because we are using ethernet, so the first file should be divided in 3 segments of 1460 and one of 120 while the second file is divided in 2 segments of 1460 and one of 80 (at least this is what happen if tcp send one file only). 现在假设客户端需要的文件为4500字节和3000字节,而tcp的MSS为1460字节,因为我们使用的是以太网,因此第一个文件应分为3段,分别为1460和120,而第二个文件为分为2段1460和80段之一(至少这是tcp仅发送一个文件的情况)。 In this situations how many segments tcp will send? 在这种情况下,tcp将发送多少段? The first 4 of the first file and the 3 of the second file or it will “merge” the 2 file together at first and then send that file divided? 第一个文件的前4个和第二个文件的3个,还是会首先“合并”两个文件,然后分开发送该文件? In the second case we would have a file of 7500, 5 MSS + 200 bytes. 在第二种情况下,我们将拥有7500、5 MSS + 200字节的文件。

I can't find anywhere informations about this problem. 我在任何地方都找不到有关此问题的信息。 So in the end my question how is the pattern of the segments send by tcp: 所以最后我的问题是tcp如何发送段的模式:

3 MSS -> 120 bytes -> 2 MSS -> 80 bytes Or 5 MSS -> 200 bytes 3 MSS-> 120字节-> 2 MSS-> 80字节或5 MSS-> 200字节

I can't understand how tcp could send a segment containing bytes of 2 different files. 我不明白tcp如何发送包含2个不同文件的字节的段。

I can't understand how tcp could send a segment containing bytes of 2 different files. 我不明白tcp如何发送包含2个不同文件的字节的段。

From the perspective of a user application TCP is just a byte stream and nothing is known how these bytes were delivered in packets. 从用户应用程序的角度来看,TCP只是一个字节流,而如何将这些字节以数据包的形式传递则一无所知。 At the TCP itself there is no idea of files or HTTP requests and responses. 在TCP本身,没有文件或HTTP请求和响应的概念。 The distinction between these is done at the application level instead, ie in this case at the level of the HTTP protocol. 这些之间的区别是在应用程序级别进行的,即在这种情况下,在HTTP协议级别进行。

The HTTP protocol defines that each request and response consists of a header and a body which are distinguished by an empty line. HTTP协议定义每个请求和响应都由标头和正文组成,这些标头和正文由空行区分。 The size of the body or body parts are known up-front, ie either given in the header (using the content-length field) or given before each body chunk (with transfer-encoding: chunked ). 主体或主体部分的大小是预先已知的,即在标头中给出(使用content-length字段),或者在每个主体块之前给出(使用transfer-encoding: chunked )。 This way the end of the body and thus the beginning of the next request/response can be determined by the HTTP protocol parser. 这样,可以由HTTP协议解析器确定正文的结尾,从而确定下一个请求/响应的开始。 And it does not matter at all how these data are packetized at the underlying TCP layer. 而且,这些数据如何在底层TCP层打包也没有关系。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM