Interviewer: Tell me about the difference between TCP and UDP and application scenarios

Original articles to the public starting number: "code farmers rich man", and welcomed the attention the collection, such as reprint please indicate the source!

Previous after talking with a text thoroughly get to know the TCP three-way handshake, four waved process and the principle of
the TCP and UDP difference between talk and scenes

TCP / IP transport protocols, there are two representative, are TCP and UDP.
Look at the position of the OSI seven layer protocol transport layer, and TCP / IP four-layer protocol:
OSI seven layer protocol and TCP / IP protocol four

So the difference between TCP and UDP and usage scenarios are what?
We use a chart to compare the UDP and TCP:
image

TCP

TCP is connection-oriented and reliable stream protocol. Refers to continuous data stream structure, when the application sends a message using the TCP, although the order of transmission may be guaranteed, but if no data or any interval stream to a receiving end.

TCP provides reliability for the transmission, the " Sequence Control " or " retransmission control " mechanism. Also includes a " flow control (flow rate control) ", " congestion control ", improving network utilization and many other features.

TCP has the following characteristics:

  • TCP sufficiently achieved various control functions of data transmission, retransmission control can be performed when packet loss may also be subcontracted to mess order sequence control. And these are not in UDP.
  • In addition, TCP as a protocol with a connection-oriented, will be performed only when the communication terminal when transmission data is present, can be controlled wasteful communication traffic.
  • Based on these mechanisms of TCP, IP network on this connection can be realized without a high reliability of communication ( mainly through testing and, sequence number, acknowledgment, retransmission control, connection management and window control mechanisms implemented).

UDP

UDP 是面向报文的,所谓面向报文,是指面向报文的传输方式是应用层交给UDP多长的报文,UDP就照样发送,即一次发送一个报文。因此,应用程序必须选择合适大小的报文。若报文太长,则IP层需要分片,降低效率。若太短,会是IP太小。

UDP 是不具有可靠性的数据报协议,细微的处理它会交给上层的应用去完成。在 UDP 的情况下,虽然可以确保发送消息的大小,却不能保证消息一定会到达。因此,应用有时会根据自己的需要进行重发处理。

UDP有以下特点:

  • UDP 不提供复杂的控制机制,利用 IP 提供面向无连接的通信服务。
  • 传输途中出现丢包,UDP 也不负责重发。
  • 当包的到达顺序出现乱序时,UDP没有纠正的功能。
  • 并且它是将应用程序发来的数据在收到的那一刻,立即按照原样发送到网络上的一种机制。即使是出现网络拥堵的情况,UDP 也无法进行流量控制等避免网络拥塞行为。
  • 如果需要以上的细节控制,不得不交由采用 UDP 的应用程序去处理。
  • UDP 常用于以下几个方面:
    • 1.包总量较少的通信(DNS、SNMP等);
    • 2.视频、音频等多媒体通信(即时通信);
    • 3.限定于 LAN 等特定网络中的应用通信;
    • 4.广播通信(广播、多播)。

UDP 和 TCP 的应用

他们的应用如下图:
image

总结:

TCP 和 UDP 的优缺点无法简单地、绝对地去做比较:TCP 用于在传输层有必要实现可靠传输的情况;
而在一方面,UDP 主要用于那些对高速传输和实时性有较高要求的通信或广播通信。TCP 和 UDP 应该根据应用的目的按需使用。

最后

If you harvest the article, you can forward the collection, and this is definitely my writing! In addition the public can follow me number "code farmers rich man" (Search id: coder2025), I will continue to output Python, server architecture, basic computer (MySQL, Linux, TCP / IP ) of the original article

I am concerned about the scan code: code farmers rich brother

Guess you like

Origin www.cnblogs.com/cooffeeli/p/TCP_VS_UDP.html