This is the 28th day of my participation in the August Text Challenge.More challenges in August

πŸ“– the

My journey - is the star of the sea!

How many roads I will walk, how many mountains I will conquer to find myself, how many times I will fail, how many times I will start again, and whether it all makes sense, I will wait patiently, I prepare for myself, the journey that leads to my dreams and hopes. Do not burn yourself out, my stars, wait for me.

Today, let’s shareTCP protocol 与 UDP protocol., welcome to pay attention!

TCP protocol and UDP protocol and TCP/IP protocol connection, many people have been said that TCP protocol and UDP protocol difference, I think this is not clear from the nature of network communication! TCP/IP is a protocol cluster. UDP is just one of them. It is named TCP/IP because TCP and IP are two very important protocols, so it is named after him. The TCP/IP protocol set includes the application layer, transport layer, network layer, and network access layer.


πŸŒ‚ application layer

  1. Hypertext Transfer Protocol (HTTP) : the basic protocol for the World Wide Web;
  2. File transfer (TFTP Simple File Transfer Protocol)
  3. Telnet provides remote access to other hosts. It allows users to log in to an Internet host and execute commands on the host.
  4. Network management (SNMP), which provides methods for monitoring network devices, as well as configuration management, statistics collection, performance management, and security management.
  5. Domain name System (DNS), which is used to translate domain names and their public broadcast network nodes into IP addresses on the Internet.

✨ network layer

  1. Internet Protocol (IP);
  2. Internet Control Information Protocol (ICMP);
  3. Address resolution Protocol (ARP);
  4. Reverse Address resolution Protocol (RARP).

🀳 Network access layer

The network access layer is also called the host-to-network layer. The functions of the network access layer include hardware mapping between IP addresses and physical addresses and encapsulation of IP addresses into frames. The network access layer defines connections to physical media based on network interfaces of different hardware types. Of course, I am not perfect here, TCP/IP protocol is originally a knowledge, each branch is a very complex process, but every student learning software development is necessary to understand some.


πŸ™ŒTCP protocol ε’Œ UDP protocol.The difference between

Transmission Control Protocol (TCP) is a connection-oriented Protocol, that is, before sending or receiving data, a reliable connection must be established with the peer party. A TCP connection must be set up through three “conversations”. The process is very complicated. Here is a simple description of the process:

  1. Host A sends A connection request packet to host B: “I want to send you data, ok?” This is the first dialogue;
  2. Host B sends host A A packet agreeing to connect and asking for synchronization (synchronization is when two hosts are sending and one is receiving, coordinating work) : “Yes, when will you send?” This is the second dialogue;
  3. Host A sends A data packet to confirm host B’s request synchronization: “I send now, you then!” This is the third dialogue.

The purpose of the triple chat is to synchronize the sending and receiving of data packets. After the triple chat, host A sends data to host B.

TCPThree handshake process

  1. First handshake: Host A requests host B to establish A connection by sending host B A data segment containing A flag bit of the synchronized serial number. Through this data segment, host A tells host B two things: I want to communicate with you; You can respond to me with the serial number as the starting data segment.
  2. The second handshake: Host B receives the request from Host A and responds to host A with A data segment with the ACK and SYN flag bits, which also tells host A two things: I have received your request and you are ready to transmit data; You’re gonna respond to me with that serial number as the starting data segment
  3. Third handshake: After host A receives this segment, it sends an acknowledgement acknowledgement that it has received the segment from host B: “I have received the reply and I will now begin transmitting the actual data, so the three-way handshake is complete and host A and host B can transmit the data.

Three handshake features

If there is no data at the application layer, the SYN bit is set to 1 only when TCP establishes a connection. After the handshake, the SYN bit is set to 0.

πŸš€ to teach youmermaidDraw aTCPThree-way handshake process diagram


Have want to learn the message, people I give a tutorial hee hee

  • A: Client — establish TCB active opening
  • B: server – establishes TCB passive open
Note left of A: TCB ->>B: Note left of B: TCB -> B: SYN=1, SEq =x B ->>A: SYN=1, ACK=1, SEq =y, ACK= x+1 A ->>B: ACK=1, SEq =x+1, ACK= y+1 Note over A,B: SYN=1, ACK=1, SEq =y, ACK= x+1

TCPIt takes three handshakes to establish a connection and four handshakes to disconnect

  1. First: When host A completes data transmission, the host controls the bitFINIf 1 is set, the request for stopping the TCP connection is put forward.
  2. Second time: After receiving a FIN, host B responds to the FIN, confirming that the TCP connection in this direction will be closed, and sets ACK to 1.
  3. The third time: end B will make another closing request in the opposite directionFINBuy 1;
  4. Fourth time: Host A confirms host B’s request and sets ACK to 1.

As can be seen from TCP’s three-way handshake and four-way disconnection, TCP uses connection-oriented communication mode, which greatly improves the reliability of data communication, making the sending data end and the receiving end interact before formal data transmission, laying a reliable foundation for formal data transmission.

Noun explanation

  1. ACK 是 TCP headerTo confirm the data. Acknowledgement sent by the destination is used to tell the sender that all data segments preceding the sequence number have been received. For example, if the confirmation number is X, the first X-1 data segment is receivedACK=1The confirmation number is valid only whenACK=0, the confirmation number is invalid, and data is retransmitted to ensure data integrity.
  2. SYNSynchronize the serial number,TCPSet this position to 1 when establishing the connection.
  3. FINThe sending end completes the sending task bit whenTCPTo complete the data transfer requires disconnection, the party proposing disconnection will place this position 1.

TCP header structure:

  • Source port 16-bit;
  • Destination port 16 bits;
  • Serial number 32 bits;
  • The response sequence number is 32 bits;
  • The TCP header length is 4 bits.
  • Six reserved;
  • Control code 6 bits;
  • Window size 16 bits;
  • Offset 16 bits;
  • Checksum 16 bits;
  • Option 32 bits (optional);

We can drawThe TCP headerThe minimum length is 20 bytes.

✨User Data Protocol (UDP)

  1. UDP is a connectionless protocol that transmits data without establishing a connection between the source and the end. When it wants to transmit, it simply grabs the data from the application and throws it on the network as quickly as possible. On the sending side, the speed at which UDP can transmit data is limited only by the speed at which the application can generate the data, the power of the computer, and the transmission bandwidth; At the receiving end, UDP queues each message segment, and the application reads one message segment at a time from the queue.
  2. Since no connection is established for data transmission, there is no need to maintain connection state, including sending and receiving state, so a single server machine can simultaneously transmit the same message to multiple clients.
  3. The header of a UDP packet is short, only 8 bytes, with little overhead compared to the 20 bytes of a TCP packet.
  4. Throughput is not regulated by the congestion control algorithm, but is limited only by the rate of data generated by the application software, transmission bandwidth, and the performance of the source and terminal hosts.
  5. UDP uses best effort delivery, which means reliable delivery is not guaranteed, so hosts do not need to maintain complex linked state tables (which have many parameters).
  6. UDP is packet oriented. The UDP packets sent by the sender to the application are forwarded to the IP layer after the header is added. Instead of splitting or merging, the boundaries of these messages are preserved, so the application needs to select the appropriate message size.

The ping command is often used to test whether the TCP/IP communication between two hosts is normal. In fact, the ping command sends UDP packets to the host of the other host, and then the host of the other host confirms the receipt of the packets. If the message whether the packets have arrived is returned in time, the network is normal. The ping command is used to check whether hosts can communicate with each other. If a host cannot be pinged, the host cannot be connected. The ping command uses IP and Network Control Information Protocol (ICMP), so it does not involve any transport protocols (UDP/TCP) or applications. It sends an ICMP echo request message to the destination host. ICMP: The destination host must return an ICMP reply message to the source host. If the source host receives a reply within a certain amount of time, the host is considered reachable.

UDP header structure:

  • The source port has 16 bits
  • Destination port 16 bits
  • The length of the 16
  • Checksum 16 bits

πŸ’– summary


The differences between TCP and UDP:

  1. Connection-based and connectionless;
  2. Requirements on system resources (more TCP and less UDP);
  3. UDP program structure is simple;
  4. Flow mode and datagram mode;
  5. TCP ensures data correctness while UDP may lose packets.
  6. TCP guarantees data order, UDP does not.

Finally, thank you for your patience to watch the end, leave a thumbs-up collection is your biggest encouragement to me!


πŸŽ‰ finally

  • For more references, see here:Chen Yongjia’s blog

  • Like the small partner of the blogger can add a concern, a thumbs-up oh, continue to update hey hey!