First, what is TCP, what does he do?
I.e., transmission control protocol TCP (Transmission Control Protocol) is a connection-oriented, reliable transport layer protocol based on the byte stream.
TCP is a transport protocol to provide reliable end to end byte stream over the unreliable Internet specifically designed.
Single Internet network are very different, because different parts of the Internet may have distinct topologies, bandwidth, latency, packet size and other parameters. TCP design goal is to be able to dynamically adapt to these characteristics of the Internet, and have for a variety of fault robustness.
Often you need a reliable application layer between different hosts, like pipelines are connected, but the IP layer does not provide a mechanism for flow, but to provide an unreliable packet switching.
Maximum application layer gateway transmits to the TCP transport layer, data stream represented by 8-bit bytes, and the TCP data stream is partitioned into segments of suitable length (typically by calculating the data link layer network connection to restrict the transmission unit (MTU) in). After the result of TCP packets to the IP layer, it has come through the network packet to the TCP layer entity receiving end.
To ensure TCP packet loss does not occur, give each packet a sequence number, but also ensures that the serial number sequentially transmitted to the receiving end of the packet reception entity. then
Entity receiving terminal has successfully received a return packet corresponding acknowledgment (the ACK); If the sender entity acknowledgment is not received within a reasonable round-trip time (RTT), then the corresponding data packet is assumed to have been lost to It will be retransmission. TCP checksum with a function to verify whether the data error; checksum is calculated for the transmission and reception.
Each machine supporting TCP has a TCP transport entity. A user process or part of a library when the kernel can process TCP entity. In all these cases, it manages the interface between the TCP stream, and the IP layer. TCP transport entity receives a local process of the user data stream, dividing them into no more than 64KB (IP and TCP header actually removed, usually not more than 1460 data bytes) of segments, each segment in a separate IP datagrams send. When TCP datagram contains data reaches a machine, which is handed to the TCP transport entity, TCP transport entity to reconstruct the original byte stream. For simplicity, we sometimes use only TCP to represent the TCP transport entity (a piece of software) or the TCP protocol (a set of rules). According to the semantic context you should be able to clearly infer its actual meaning. For example, in the ‘user submits data to the TCP’ this sentence, it is clear here refers to the TCP entity.
IP layer does not guarantee that the data packet must have been submitted to the receiving side correctly, not just how the transmission rate of data packets blocks. It is responsible for the minutes of TCP fast enough to transmit data packets in order to use network capacity, but not cause network congestion: And, after the TCP timeout to retransmit the data submitted no report. Even if they are correct submitted data reported, there may be the wrong question, which is the responsibility of TCP, it must be received datagrams reassembled into the correct order, in short, TCP must provide reliability, good performance, what most users expect and they did not provide IP functionality.
Second, the main features
When a packet for transmitting the application layer gateway to the TCP transport layer, a data stream of 8-bit bytes, TCP data stream put into an appropriate length. After the TCP packet is passed to the IP layer, by it through the network packet to the TCP layer entity receiving end.
TCP is a communication protocol for the wide area network, when the object spanning the plurality of communication networks, communication between two endpoints to provide a communication mode has the following characteristics:
(1) Based on flow mode;
(2) for connection;
(3) reliable communication;
(4) network in a bad situation because retransmission system to minimize bandwidth overhead caused;
(5) a communication connection is maintained for the two endpoints, without consideration of the intermediate segments and nodes.
To meet these characteristics of TCP, TCP protocol made the following provisions:
① Data slice: the transmitting end user data fragments for recombination at the receiving end, the size of the slice is determined and controlled by the TCP Segmentation and Reassembly;
② arrival confirmation: when the receiving end receives fragmented data, sends an acknowledgment to the transmitting end according to the fragment data number;
③ retransmission timeout: The sender timeout timer starts transmission time slice, if the time-out after not receiving a corresponding acknowledgment timer, the retransmission slice;
④ sliding window: TCP receiving buffer connected to each side of the space are fixed, the other end of the receiving terminal allows only transmission and reception side can receive data buffer, TCP provides flow control on the basis of the sliding window, causing the host to prevent faster than slow host buffer overflow;
⑤ disorder treatment: When out of order may be transmitted as IP datagrams of TCP fragments arrive, TCP will reorder the received data, the received data in the correct order to the application layer;
⑥ process is repeated: as an IP datagram to transmit the TCP repeated fragmentation occurs, the receiver must discard duplicate TCP data;
⑦ Data Checksum: TCP checksum holding it and the header and data, which is a checksum and end purpose of detecting any change in the data transmission process. If the checksum is received by the error and slices, TCP discards the fragment, and confirm receipt of this segment of the end of a timeout and retransmits lead.
TCP is the transport layer protocol in the Internet, establish a connection using a three-way handshake protocol. When the active party issuing a connection request SYN, SYN + ACK waiting for the other party to answer, and finally performs SYN ACK confirmation on the other side. This method of establishing connections can prevent erroneous connection, TCP flow control protocol used will be the size of the East window protocol.
TCP three-way handshake is as follows:
(1) The client sends a SYN (SEQ = x) packet to the server, enters SYN_SEND state.
(2) the server receives a SYN packet, a response to SYN (SEQ = y) ACK (ACK = x + 1) packets, enters SYN_RECV state.
(3) the client receives the server SYN packet, a response ACK (ACK = y + 1) packets, enters the Established state.
Three-way handshake is completed, TCP client and server to establish a successful connection, you can begin transmitting the data. Figure:
The connection is terminated
Establish a connection requires three-way handshake, and the weight of a connection to go through a four-way handshake, which is caused by the TCP half-closed (half-close) of. FIG using the following procedure.
(1) An application process first call to close, said the end of the implementation “Active Off” (active close). The end TCP then sends a FIN partial section, showing the distribution of data is completed.
(2) receives this performs peer FIN “passive shutdown” (passive close), the FIN confirmed by TCP.
Note: FIN also serves as a receiving end of file (end-of-file) is passed to the receiving end of the application process, on any other packets queued for process applications received after, because, FIN receiving means means that the amount of application process is no longer connected to the respective additional data may be received.
(3) a period of time, receiving this end of file application process will close its call to close the socket, which causes it also sends a TCP FIN.
(4) receives this final original FIN sending end TCP (i.e., that end of the active close) to confirm the FIN. Since each direction and a need for a FIN ACK, and therefore typically requires four sub-sections.