<>TCP and UDP What is it? ? What's the difference ?
<>1.TCP agreement
Transmission control protocol (TCP,Transmission Control Protocol) Is a connection oriented , reliable , Transport layer communication protocol based on byte stream .
Byte stream service (Byte Stream Service) It means to facilitate transmission , Dividing large blocks of data into message segments (segment) Manage packets for units .
Reliable transmission service refers to , Be able to transmit data to each other accurately and reliably . Namely TCP The protocol divides the data in order to make it easier to transmit big data , and TCP
The protocol can confirm whether the data is finally sent to the other party . It's like making a phone call , Wait for the other party to answer the phone , To communicate with each other .
High requirements for data accuracy , The speed can be relatively slow , Can choose TCP
<>tcp Characteristics of the protocol
*
Connection oriented
Connection oriented , It means that a connection must be established at both ends before sending data . The way to establish a connection is “ Three handshakes ”, This establishes a reliable connection . Establish connection , It lays a foundation for reliable data transmission .
*
Only unicast transmission is supported
Each TCP A transport connection can only have two endpoints , Only point-to-point data transmission can be performed , Multicast and broadcast transmission modes are not supported .
*
Byte oriented stream
TCP No UDP Messages are transmitted independently , Instead, it is transmitted in byte stream without retaining the message boundary .
*
Reliable transmission
For reliable transmission , Judge packet loss , Error code depends on TCP Segment number and confirmation number .
TCP In order to ensure the reliability of message transmission , Just give each package a serial number , At the same time, the sequence number also ensures the sequential reception of packets transmitted to the receiving entity . Then, the receiving entity sends back a corresponding acknowledgement for the successfully received bytes (ACK); If the sending entity is within a reasonable round-trip delay (RTT) No confirmation received within , Then the corresponding data ( The assumption is lost ) Will be retransmitted .
*
Provide congestion control
When the network is congested ,TCP It can reduce the rate and amount of data injected into the network , Ease congestion
*
TCP Provide full duplex communication
TCP Allows applications on both sides of the communication to send data at any time , because TCP Caches are provided at both ends of the connection , Used to temporarily store two-way communication data . of course ,TCP A data segment can be sent immediately , You can also cache for a period of time to send more data segments at a time ( The maximum segment size depends on MSS)
<>2. UDP What is the agreement
Internet The protocol set supports a connectionless transport protocol , This protocol is called user datagram protocol (UDP,User Datagram Protocol).UDP
It provides a way for applications to send packages without establishing a connection IP Datagram method . Similar to texting . Whether the other party turns on or not , The sender will display successful sending .
although UDP did not TCP Accurate transmission , But it can also be useful in many places with high real-time requirements .
<>UDP Characteristics of the protocol
*
No connection
Know each other's IP And port number are transmitted directly , No connection required .
*
unreliable
There is no confirmation mechanism , No retransmission mechanism ; If the segment cannot be sent to the other party due to network failure UDP The protocol layer will not return any error information to the application layer .
*
Data oriented message
Unable to flexibly control the number and number of data read and write , Application layer to UDP How long is the message , UDP Send as is , Neither split , Will not merge .
Data reception is not flexible enough , However, the two packets can be clearly distinguished , Avoid sticking problems .
*
There is unicast , Multicast , Broadcast function
UDP More than one-to-one transmission mode is supported , It also supports one to many , Many to many , Many to one , in other words UDP Unicast is provided , Multicast , Broadcast function .
<>3. TCP and UDP Differences between agreements
*
Differences in connection
TCP Connection oriented ( To make a call, dial up first to establish a connection );UDP Is connectionless , That is, there is no need to establish a connection before sending data
*
Differences in safety
TCP Provide reliable service . in other words , adopt TCP Data transferred by connection , Error free , Not lost , No repetition , And arrive in order ;UDP Best effort delivery , I.e. reliable delivery is not guaranteed
Tcp Pass checksum , Retransmission control , Serial number identification , sliding window , The confirmation response realizes reliable transmission . Such as retransmission control in case of packet loss , It can also control the order of the disordered subcontracting .
*
Differences in transmission efficiency
UDP It has good real-time performance , Work efficiency ratio TCP high , It is suitable for high-speed transmission and real-time communication or broadcast communication .
*
Difference in the number of connected objects
Each TCP Connections can only be point-to-point ;UDP Support one-to-one , One to many , Many to one and many to many interactive communication
*
Differences in resource requirements
TCP There are many requirements for system resources ,UDP Less requirements for system resources .
Technology