TCP and UDP difference (interview)

1.TCP

1.1 TCP advantage

Reliable and stable.
TCP Reliable reflected in the TCP before passing the data, there will be three-way handshake to establish a connection, but at the time of data transfer, have confirmed that window, retransmission, congestion control mechanisms, in data transfer finished, it will be used to disconnect conserve system resources.

1.2 TCP's shortcomings

Slow, low efficiency, high system resources, vulnerable to attack.
TCP before passing the data must first build connections, which will consume time, but also in the data transfer, acknowledgment mechanism, retransmission mechanism, and congestion control mechanisms will consume a lot of time, but also to maintain all transmissions on each device connection, in fact, each CPU, memory and other hardware resources connected to the system will occupy. And because there are TCP acknowledgment mechanism, three-way handshake, which also led to TCP vulnerable to exploitation, to achieve DOS, DDOS, CC attacks.

2.UDP

2.1 UDP advantage

Fast, a little safer than TCP.
UDP TCP three-way handshake is not confirmed, the window, the retransmission, the congestion control mechanism, UDP is a stateless protocol transmission , so it is very fast when transferring data. Without these mechanisms of TCP, UDP than TCP vulnerabilities being exploited by attackers would be less. UDP attacks but also can not be avoided, such as: UDP Flood attack.

2.2 UDP's shortcomings

Unreliable and unstable.
Because there is no UDP TCP those reliable mechanism, when the data transfer, if the network quality is not good, it would be easy to packet loss .

3.TCP and UDP difference

TCP UDP
Connection-oriented Non-connection-oriented
Reliable (to ensure data correctness) Unreliable (possible loss)
Inefficient (slow) High efficiency (fast)
Order to ensure data No guarantee of the order
High system resources Low system resources
Byte stream and Message-oriented
Transfer large amounts of data Transfer small amounts of data
Reliable full-duplex channel Unreliable channel
Browser, file transfer Micro-channel video, voice,

4. Summary

1, TCP connection-oriented (e.g., dial-up connection is established first call); the UDP is connectionless, i.e. without establishing a connection before sending data.

2, TCP provides reliable service. Connected through TCP data transfer, error-free, not lost, not repeat, and arrive out of order; UDP best effort, that does not guarantee reliable delivery.

. 3, TCP byte stream and, in fact, the TCP byte stream data as a series of unstructured; is for the UDP packets.
UDP no congestion control , and therefore does not cause congestion source host of the network is to reduce the transmission rate (useful for real-time applications such as IP telephony, real-time video conferencing, etc.)

4, each TCP connection can only point to point; UDP support one to one, one to many, many-to-many communication and interaction

5, TCP header of 20 bytes of overhead; small UDP header overhead, only 8 bytes

6, a logical communication channel is TCP reliable full-duplex channel, UDP is unreliable channel

The application scenario

5.1 When should you use TCP?

When there are quality requirements for network communications using TCP , such as: the accuracy of the entire data to be passed to the other side, which is often some of the requirements for reliable applications, such as file transfer protocol HTTP, HTTPS, FTP, etc., POP, SMTP, etc. mail transfer protocol. In daily life, common applications use the TCP protocol are as follows: browser, use HTTP FlashFXP, using FTP Outlook, using POP, SMTP Putty, use Telnet, QQ file transfer.

5.2 When should you use UDP?

When using the UDP network communication quality when less demanding , requiring network communication speed can be fast as possible, then you can use UDP. For example, in daily life, common application using UDP protocol are as follows: QQ QQ voice video (real-time delivery)
and some application scenarios will be used for less demanding reliability UPD, such as long video, required rate

Published 28 original articles · won praise 1 · views 526

Guess you like

Origin blog.csdn.net/qq_40575302/article/details/104588810