Written before the HTTP protocol

Source: Internet
Author: User

1. Network model

The OSI model, the Open System Interconnect Reference Model (OSI), is an open Systems Interconnect reference Model developed jointly by the International Organization for Standardization (ISO) and interconnect (CCITT), It provides a framework of functional structure for the open interconnection information system. It is from low to high: physical layer, data line layer, network layer, transport layer, Session layer, presentation layer and application layer.

Physical layer: The physical layer is the lowest layer in the OSI model of the computer network. The physical layer provides for the creation, maintenance, demolition of the physical link required to transmit the data, and the provision of mechanical, electronic, functional and normative characteristics.

Data Link layer: The Data link layer is the second layer in the OSI Reference Model, between the physical layer and the network layer. The data link layer provides services to the network layer on the basis of the services provided by the physical layer, and its most basic service is to reliably transfer the data from the network layer to the target network layer of the neighboring nodes.

Network layer: The network layer in the Data Link layer provides two adjacent endpoints between the data frame transfer function, the further management of data communication in the network, will be managed from the source side through a number of intermediate nodes to the destination, so as to provide the transport layer of the most basic end-to-end data services.

Transport layer: Achieve end-to-end data transfer.

Session Layer: Use the services provided by the Transport layer to synchronize the application establishment and maintenance sessions.

Presentation layer: A service that represents a layer that provides a representation of the information that is transferred between applications, and is concerned only with the syntax and semantics of the information emitted.

2. TCP protocol:

The TCP protocol (shorthand for transmission Control protocol/internet Protocol) is a connection-oriented, reliable transport-layer communication protocol based on byte-stream. TCP packages the user data into a message, sends a timer after it is sent, confirms the data received at the other end, re-sorts the unordered data, and discards duplicate data.

Features of TCP:

TCP protocol is a connection-oriented Transport layer protocol

Each TCP connection can only be made up of two endpoints, and each TCP connection can only be a point-to-point

TCP provides reliable delivery of services

TCP provides full-duplex communication.

byte stream oriented

TCP Three-time handshake:

The first handshake: the client sends a connection request packet to the server, clients place the token bit SYN at 1, randomly generates a value of seq=j, and sends the data packets to server,client into the syn_sent state, waiting for the server to confirm.

Second handshake: The server receives the message sent by the client, and the Syn=1 notifies the client that a connection is required, then allocates resources for the connection. and send to the client a SYN and ACK are set to 1 of the TCP packets, sets the initial sequence number y=0, the confirmation sequence is set to the last client sent over the order number (SEQ) plus 1.

Third handshake: The client receives a packet from the server to check if the confirmation number (ACK) is correct, which is the first time the SEQ is sent plus 1. And whether the flag bit ACK is 1. If correct, the server sends the confirmation packet again, the ACK flag bit 1, the acknowledgment number (ACK) =k+1, and sends the data packets to Server,server check if the ACK is K+1,ack is 1, if correct, the connection is established successfully, The client and Sserver enter the established state, complete three handshake, and then the client and server can start transmitting data.

                        

TCP four times wave:

Four waves to terminate a TCP connection means that when a TCP connection is disconnected, a total of 4 packets are sent by the client and the server to confirm the disconnection of the connection. Because the TCP connection is full-duplex, each direction must be closed separately, the principle is that when a party completes the data sending task, send a fin to terminate the connection in this direction, the receipt of a fin just means that there is no data flow in this direction (no longer receiving data), and does not mean that the connection is disconnected, However, the TCP connection is still capable of sending data until the fin is sent in this direction. The first party to close will perform an active shutdown, while the other side performs a passive shutdown. Its processes such as

                        

First wave: The client sends a fin to turn off the client to server data transfer, and the client enters the fin_wait_1 state.

Second wave: After receiving fin, the server sends an ACK to the client, confirming that the serial number is received +1,server enter the Close_wait state.

Third wave: The server sends a fin to shut down the server-to-client data transfer, and the server enters the Last_ack state.

The fourth wave: After the client receives fin, the client enters the TIME_WAIT state, then sends an ACK to the server, confirming that the serial number is received sequence number +1,server enter close status, four times to complete the wave.

The above is the active shutdown, the other side of the passive shutdown situation, in practice, there will also be active closed scene, the specific process such as:

                         

Written before the HTTP protocol

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.