Two, http and tcp communication http relationship

(TCP / IP communication data flows)

Data related to the package:

The client sends a request, from the application layer, has been to link layer, each layer will be marked with the header information belongs to the layer; the other hand, between the transmission terminal receiving layers, each layer will be removed after the layer header information

 

 

HTTP communication mechanism is in a complete HTTP communication process, complete the following seven steps between the Web browser and the Web server:

1. establish a TCP connection
before the work began HTTP, Web browser must first establish a Web server via a network connection, which is done through TCP port number TCP connection is generally 80.

2. Web browser sends a request to the Web server command 
once a TCP connection is established, Web browser sends a request command to the Web server. For example: GET / sample / hello.jsp HTTP / 1.1.

3. Web browser sends a request headers 
browser sends its request after the command, but also send some other form of information to the Web server header information, then the browser sends a blank line to inform the server, it's over the transmitting header information.

4. Web server answers 
the client request to the server, the server will send the response back to the client, HTTP / 1.1 200 OK, the response of the first part is the protocol version number and the response status code.

5. Web server sends the response headers 
as client request along with information about themselves, the server will send a response along with data on its own and the requested documents to the user.

6. Web server sends data to the browser 
Web server after sending headers to the browser, it sends a blank line to represent the header information to send this to the end, then, it is a response to the Content-Type header described transmitting the actual data format requested by the user.

7. Web server closes the TCP connection 
Generally, once the Web server sends the requested data to the browser, it is necessary to close the TCP connection, then the browser, or if the server on which the header information is added to this line of code: Connection: keep-alive

TCP connection after sending remains open, so the browser can continue to send requests over the same connection. Remains connected saves time required to establish a new connection for each request, further saving network bandwidth.

Guess you like

Origin www.cnblogs.com/dashu123/p/11564042.html