TCP (transmission Control Protocol, transmission Protocol) is a connection-oriented protocol,
In other words, a reliable connection must be established with each other before sending or receiving data.
A TCP connection has to be three "conversations" to build, and the process is very complex and simply describes the simple process of three conversations:
A---> B
Host A sends a connection request packet to Host B: "I want to send you data, OK?" "This is the first dialogue;
A <---B
Host B sends a consent connection to host A and requires synchronization (synchronization is two hosts one in the send, one in the receiving, coordination work)
The packet: "Can, when do you send?" "This is the second dialogue;
A---> B
Host A then sends a packet to confirm that Host B's requirements are synchronized: "I'll send it now, you go on!" ", this is the third dialogue.
Three times the purpose of the "conversation" is to synchronize the sending and receiving of packets, and after three "conversations", host a formally sends the data to Host B.
In detail, it is:
3 Handshake process for TCP connect connection
1 Host A to host B by sending a data segment containing a flag bit of the serial number to Host B, to host B to request a connection, through this data segment,
Host A tells Host B two things: I want to communicate with you, you can use which serial number as the starting data segment to respond to me.
2 when Host B receives a request from host A, it responds to host A with a data segment with a ACK (ACK) and a synchronous sequence number (SYN) flag bit, and also tells host a two things:
I have received your request, you can transfer the data, you need to use which pins XLR serial number as the starting data segment to respond to my
3 When host a receives this data segment, it sends a confirmation reply confirming that the data segment of Host B has been received: "I have received a reply and I am now going to start transmitting the actual data.
So 3 times the handshake is complete, and host A and Host B can transfer the data.
3-Time handshake features
No data for the application tier
SYN This flag bit will only be set when the TCP build connection is 1
SYN flag bit is set 0 after handshake completes
TCP disconnects to be made 4 times
1 when host a completes the data transfer, the control bit fin is set to 1 and a request to stop the TCP connection is made
2 Host B responds to the FIN after it receives it, confirming that the TCP connection to the side is closed and the ACK is set to 1
3 by the B-end and then forward the reverse direction of the closing request, the Fin 1
4 Host a confirms the request of Host B, the ACK is set to 1, and the closing of the double direction closes.
It can be seen from the three handshake and four disconnects of TCP that TCP uses the connection-oriented communication method, which greatly improves the reliability of data communication, and makes the transmitting end
And the receiving end of the data before the formal transmission of the interaction, for the formal transmission of data to lay a reliable foundation
noun explanation
ACK one of the control bits of the TCP header to confirm the data. Confirm that the destination is issued, and use it to tell the sender that the data segment before the serial number
All received. For example, the confirmation number is x, that is, the first X-1 data segment received, only when ack=1, the confirmation number is valid, when ack=0, the confirmation number is invalid, this will require retransmission of data, to ensure the integrity of the data.
SYN Synchronous serial number, TCP establishes this position 1 when establishing a connection
The FIN sender completes the send task bit, and when TCP completes the data transfer needs to disconnect, the side that proposes the disconnection will have this position 1
UDP (User data Protocol, Subscriber Datagram Protocol)
(1) UDP is a non-connected protocol that transmits data before the source and terminal do not establish a connection, when it wants to transfer the simple to crawl data from the application, and throw it to the network as soon as possible. On the sending side, UDP transmits data at a speed that is limited by the speed of the application-generated data, the ability of the computer, and the transmission bandwidth; At the receiving end, UDP places each message segment in the queue and the application reads a message segment from the queue each time.
(2) Because the transfer data does not establish a connection, so there is no need to maintain the connection state, including the sending and receiving status, so a server can simultaneously transmit the same message to multiple clients.
(3) The header of the UDP packet is very short, with only 8 bytes, and the extra overhead of 20 byte packets relative to TCP is small.
(4) Throughput is not regulated by congestion control algorithms, only the rate of data generated by the application software, the transmission bandwidth, the source side and the performance limit of the terminal host.
(5) UDP uses the best effort to deliver , that is, does not guarantee reliable delivery, so the host does not need to maintain a complex link state table (there are many parameters).
(6) UDP is message-oriented . The sender's UDP message to the application is delivered down to the IP layer after the header is added. Instead of splitting and merging, the boundaries of these messages are preserved, so the application needs to select the appropriate message size.
We often use the "ping" command to test the TCP/IP communication between the two hosts is normal, in fact, the principle of "ping" command is to send UDP packets to the other host, and then the other host to confirm the receipt of the packet, if the packet arrives timely feedback back, then the network is through.
Summary of the differences between TCP and UDP:
1. Based on connection and no connection;
2. Requirements for system resources (more TCP, less UDP);
3.UDP program structure is relatively simple;
4. Flow mode and datagram mode;
5.TCP guarantees data correctness, UDP may drop packets, TCP guarantees data order, UDP is not guaranteed.
more information on TCP and UPD:
TCP---Transmission Control Protocol, providing a connection-oriented, reliable byte-stream service. Before the customer and the server Exchange data with each other, a TCP connection must be established between the two parties before the data can be transferred. TCP provides time-out re-send, discard duplicate data, test data, flow control and other functions to ensure that data can be transmitted from one end to the other.
UDP---User Datagram Protocol, is a simple transport layer protocol for datagram. UDP does not provide reliability, it simply sends the application to the IP layer's datagram, but does not guarantee that it will reach its destination. Because UDP does not have to establish a connection between the client and the server before transmitting the datagram, and there is no mechanism such as time-out retransmission, the transmission speed is very fast.
The main difference between UDP and TCP is that UDP does not necessarily provide reliable data transfer. In fact, the agreement does not guarantee that the data will arrive at the destination accurately. UDP is very effective in many ways. UDP can be used when the goal of a program is to transfer as much information as possible, where any given data is of relatively low importance. ICQ Short message sends a message using the UDP protocol.
Many programs will use a separate TCP connection and a separate UDP connection. Important state information is sent with a reliable TCP connection, while the primary traffic is sent over UDP.
The purpose of TCP is to provide reliable data transfer and to maintain a virtual connection between the devices or services that communicate with each other. TCP is responsible for data recovery when packets are received unordered, lost, or destroyed during delivery. It accomplishes this by providing a sequence number for each packet it sends. Remember that the lower network layer treats each packet as a separate unit, so the packets can be sent along a completely different path, even if they are part of the same message. This kind of routing is very similar to the way the network layer handles fragmentation and reassembly of packets, just a higher level.
To ensure that data is received correctly, TCP requires an acknowledgment (that is, an ACK) to be sent back when the destination computer successfully receives the data. If the corresponding ACK is not received within a certain time limit, the packet is re-routed. If the network is congested, this re-transfer will result in duplicate packets being sent. However, the receiving computer can use the sequence number of the packet to determine whether it is a duplicate packet and discard it if necessary.
Selection of TCP and UDP
If we compare the structure of UDP packets and TCP packets, it is obvious that UDP packets do not have the complex reliability and control mechanism of TCP packets. As with the TCP protocol, the number of source ports and destination ports for UDP also supports multiple applications on a single host. A 16-bit UDP packet contains a byte-long header and the length of the data, and the checksum field makes it possible to verify the whole. (Many applications only support UDP, such as multimedia data streams, without generating any additional data, even if they know that a damaged package is not re-sent.) )
Obviously, the TCP protocol is an option when the performance of the data transfer must be in the integrity, control, and reliability of the data transfer. UDP is the best choice when it comes to the emphasis on transmission performance rather than the integrity of the transmission, such as: Audio and multimedia applications. UDP is also a good choice in cases where the data transfer time is so short that the previous connection process becomes the entire flow body, such as: DNS Exchange. Part of the reason that SNMP is built on UDP is that the designer thinks that when network congestion occurs, the lower cost of UDP gives it a better chance to transfer management data. TCP-rich functionality can sometimes lead to unpredictable performance, but we believe that TCP's reliable point-to-point connections will be used for the vast majority of network applications in the near future.
FTP protocol is a file transfer protocol, which is a standard protocol, and the FTP protocol is the application protocol standard applied to TCP/IP protocol, it is the simplest way to exchange files between computer and network.
Go The difference between TCP/IP protocol and UDP/IP protocol