TCP has the following advantages: Reliability and stability The reliability of TCP is shown in that TCP establishes a connection with three handshakes before data transfer. During data transfer, TCP provides confirmation, window, retransmission, and congestion control mechanisms. After data transfer, TCP disconnects to save system resources.

Disadvantages of TCP: TCP is slow, inefficient, occupies high system resources, and is vulnerable to attacks. Before transmitting data, TCP establishes a connection, which consumes time. In addition, during data transmission, confirmation mechanisms, retransmission mechanisms, congestion control mechanisms, etc., all consume a lot of time. Each connection consumes hardware resources such as CPU and memory. In addition, TCP has the confirmation mechanism and three-way handshake mechanism, which makes IT easy to be exploited to implement DOS, DDOS, and CC attacks.

UDP does not have the handshake, confirmation, window, retransmission, congestion control mechanisms of TCP. UDP is a stateless transport protocol, so it is very fast when transferring data. Without these mechanisms, UDP is less vulnerable to attack than TCP. However, UDP attacks cannot be avoided, for example, UDP Flood attacks……

Disadvantages of UDP: Unreliable and unstable Because UDP does not have the reliable mechanism of TCP, it is easy to lose packets during data transfer if the network quality is poor. Based on the advantages and disadvantages of the above, when should TCP be used? When there are requirements on the quality of network communication, for example, the entire data must be transmitted accurately to the other party, this is often used in some applications that require reliability.

For example, file transfer protocols such as HTTP, HTTPS, and FTP, and mail transfer protocols such as POP and SMTP. In daily life, TCP protocol is commonly used in the following applications: browser, HTTP FlashFXP, FTP Outlook, POP, SMTP Putty, Telnet, SSH QQ file transfer ………… When to use UDP: When the network communication quality is not high and the network communication speed is required, UDP can be used. For example, common UDP applications are as follows: QQ Voice QQ Video TFTP……

UPD is used in some application scenarios that do not have high reliability requirements, such as long video and speed requirements

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. Stream mode and datagram mode;

5.TCP ensures data correctness, UDP may lose packets, TCP ensures data sequence, UDP does not.

Difference between TCP and UDP TCP UDP Connection-oriented Connection-oriented Non-connection-oriented Transmission Reliability Reliability Unreliable Application scenarios The transmission speed of a large amount of data is slowCopy the code

Differences between TCP and UDP:

1, TCP connection-oriented (for example, to make a phone call to establish a connection); UDP is connectionless, that is, no connection is required before sending data

2. TCP provides reliable service. That is to say, data transmitted through the TCP connection is error-free, not lost, not repeated, and in order to arrive; 3. TCP byte stream oriented, in effect, TCP treats data as a series of unstructured byte streams. UDP is packet-oriented and does not have congestion control. Therefore, network congestion does not reduce the sending rate of the source host (useful for real-time applications, such as IP telephony and real-time video conferencing). 4. UDP support one-to-one, one-to-many, many-to-one and many-to-many interactive communication 5, TCP header overhead 20 bytes; The header of UDP has a small overhead of only 8 bytesCopy the code

6. The logical communication channel of TCP is a full-duplex reliable channel, while UDP is an unreliable channel

I hope the above content can help you. Many PHPer will encounter some problems and bottlenecks when they are advanced, and they have no sense of direction when writing too many business codes. I have sorted out some information, including but not limited to: Distributed architecture, high scalability, high performance, high concurrency, server performance tuning, TP6, Laravel, Redis, Swoft, Kafka, Mysql optimization, shell scripting, Docker, microservices, Nginx, etc. Many knowledge points can be free to share with you