TCP和UDP在现实生活中有哪些例子?

发布于 2024-10-22 01:41:20 字数 78 浏览 3 评论 0原文

我知道两者在技术层面上的区别。

但在现实生活中,谁能提供 TCP 和 UDP 应用(使用)的例子(越多越好)来展示它们的区别?

I know the difference between the two on a technical level.

But in real life, can anyone provide examples (the more the better) of applications (uses) of TCP and UDP to demonstrate the difference?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(17

笑,眼淚并存 2024-10-29 01:41:20

UDP:如果您始终获得所有数据,则任何您不太关心的

  • 内容 隧道/VPN(丢失数据包没关系 - 隧道协议会处理它)
  • 媒体流(丢失帧也可以)
  • 不关心您是否可以的游戏获取每个更新
  • 本地广播机制(在不同机器上运行的同一应用程序“发现”彼此)

TCP:几乎任何您必须获取所有传输数据的东西

  • Web
  • SSH、FTP、telnet
  • SMTP、发送邮件
  • IMAP/ POP,接收邮件

编辑:我不会费心解释这些差异,因为你声明你已经知道并且每个其他答案都解释了它:)

UDP: Anything where you don't care too much if you get all data always

  • Tunneling/VPN (lost packets are ok - the tunneled protocol takes care of it)
  • Media streaming (lost frames are ok)
  • Games that don't care if you get every update
  • Local broadcast mechanisms (same application running on different machines "discovering" each other)

TCP: Almost anything where you have to get all transmitted data

  • Web
  • SSH, FTP, telnet
  • SMTP, sending mail
  • IMAP/POP, receiving mail

EDIT: I'm not going to bother explaining the differences, since you state that you already know and every other answer explains it anyway :)

ま柒月 2024-10-29 01:41:20

UDP 正在邮局邮寄一封信。

TCP 在邮局邮寄带有回执的信件,只不过邮局管理员会按照邮寄顺序组织信件,并且只按顺序投递。

嗯,无论如何,这也是一次尝试。

UDP is mailing a letter at the post office.

TCP is mailing a letter with a return receipt at the post office, except that the post master will organize the letters in-order-of mailing and only deliver them in-order.

Well, it was an attempt anyway.

紫竹語嫣☆ 2024-10-29 01:41:20

TCP

  • 万维网 (HTTP)
  • 电子邮件 (SMTP TCP)
  • 文件传输协议 (FTP)
  • 安全外壳 (SSH)

UDP

  • 域名系统 (DNS)
  • 流媒体电影等应用程序
  • 在线多人游戏
  • IP 语音 (VoIP)
  • 简单文件传输协议 (TFTP)

TCP:

  • World Wide Web(HTTP)
  • E-mail (SMTP TCP)
  • File Transfer Protocol (FTP)
  • Secure Shell (SSH)

UDP:

  • Domain Name System (DNS)
  • Streaming media applications such as movies
  • Online multiplayer games
  • Voice over IP (VoIP)
  • Trivial File Transfer Protocol (TFTP)
眼泪淡了忧伤 2024-10-29 01:41:20

TCP 实时应用程序:

电子邮件:

原因: 假设如果某些数据包(单词/语句)丢失,我们看不懂内容,应该是靠谱的。

UDP实时应用:

视频流:

* **原因: ***假设如果某些数据包(帧/序列)丢失,我们可以理解内容。因为视频是帧的集合。对于1秒的视频应该有
25 帧(图像)。尽管我们可以理解,由于我们的想象力,有些帧丢失了。这就是 UDP 用于视频流的原因。

REAL TIME APPLICATION FOR TCP:

Email:

Reason: suppose if some packet(words/statement) is missing we cannot understand the content.It should be reliable.

REAL TIME APPLICATION FOR UDP:

video streaming:

* **Reason: ***suppose if some packet(frame/sequence) is missing we can understand the content.Because video is collection of frames.For 1 second video there should be
25 frames(image).Even though we can understand some frames are missing due to our imagination skills. Thats why UDP is used for video streaming.

夜深人未静 2024-10-29 01:41:20

经典的观点是认为 TCP 是安全的,而 UDP 是不可靠的。

但当 TCP-IP 协议用于安全关键应用时,
不建议使用 TCP,因为它可能因多种原因而因错误而停止。
而UDP让应用软件处理错误、重传定时器等。

此外,TCP比UDP有更多的处理开销。

目前,UDP用于飞机控制和飞行仪器,
在 ARINC 664 标准中也称为 AFDX(航空电子全双工交换以太网)。
在 ARINC 664 中,TCP 是可选的,但 UDP 与为 ARINC 653 标准(民用飞机中的高可靠性控制软件)设计的 RTOS(实时操作系统)一起使用。

有关在 AFDX 中使用 IP 和 UDP 进行实时控制的更多信息,
您可以阅读第 27 至 50 页
http://www.afdx.com/pdf/AFDX_Training_October_2010_Full.pdf

The classic standpoint is to consider TCP as safe and UDP as unreliable.

But when TCP-IP protocols are used in safety critical applications,
TCP is not recommended because it can stop on error for multiple reasons.
Whereas UDP lets the application software deal with errors, retransmission timers, etc.

Moreover, TCP has more processing overhead than UDP.

Currently, UDP is used in aircraft controls and flight instruments,
in the ARINC 664 standard also named AFDX (Avionics Full-Duplex Switched Ethernet).
In ARINC 664, TCP is optional but UDP is used with the RTOS (real time operating systems) designed for the ARINC 653 standard (high reliability control software in civil aircrafts).

For more information about real time controls using IP and UDP in AFDX,
you can read the pages 27 to 50 in
http://www.afdx.com/pdf/AFDX_Training_October_2010_Full.pdf

如歌彻婉言 2024-10-29 01:41:20

TCP

在得到确认之前我不会再发送数据。

这个过程很慢

它用于安全目的

例如:网络,发送邮件,接收邮件等

UDP

在这里我对确认不感到头疼。

这个过程更快,但数据可能会丢失。

示例:视频流、在线游戏等

TCP + UDP = SMTP(示例:手机、电话)

TCP

I will not send data anymore until i get an acknowledgment.

this process is slow

It is used for security purpose

example: web, sending mail, receiving mail etc

UDP

Here i have no headache with acknowledgment.

this process is faster but here data can be lost .

example : video streaming , online games etc

TCP + UDP = SMTP(example : mobile,telephone)

相守太难 2024-10-29 01:41:20

TCP 保证(按顺序)数据包传送。 UDP 则不然。

TCP - 用于需要所有数据的流量。即 HTML、图片等。
UDP - 用于在数据包丢失时不会受到太大影响的流量,即视频和视频。语音流、网络游戏的部分数据通道等

TCP guarantees (in-order) packet delivery. UDP doesn't.

TCP - used for traffic that you need all the data for. i.e HTML, pictures, etc.
UDP - used for traffic that doesn't suffer much if a packet is dropped, i.e. video & voice streaming, some data channels of online games, etc.

呆头 2024-10-29 01:41:20

TCP:

传输控制协议是一种面向连接的协议,这意味着它需要握手来建立端到端通信。一旦连接建立,用户数据就可以通过该连接双向发送。

可靠——TCP 严格仅在传输层管理消息确认、重传和超时。进行了多次传递消息的尝试。如果中途丢失了,服务器会重新请求丢失的部分。在 TCP 中,要么没有丢失数据,要么在多次超时的情况下,连接会被丢弃。 (但是,这种可靠性不包括应用程序层,在应用程序层仍然需要单独的确认流控制)

有序 – 如果通过连接按顺序发送两条消息,则第一条消息将首先到达接收应用程序。当数据段以错误的顺序到达时,TCP 缓冲区会延迟无序的数据,直到所有数据都可以正确重新排序并传递给应用程序。

重量级 – TCP 需要三个数据包才能建立套接字连接,然后才能发送任何用户数据。 TCP 处理可靠性和拥塞控制。
流式传输 – 数据作为字节流读取,没有区分指示传输到信号消息(段)边界。

TCP 的应用

万维网、电子邮件、远程管理和文件传输都依赖于 TCP。

UDP:

用户数据报协议是一种更简单的基于消息的无连接协议。无连接协议不建立专用的端到端连接。通信是通过从源到目的地单向传输信息来实现的,无需验证接收器的准备情况或状态。

不可靠——当发送UDP消息时,无法知道它是否会到达目的地;它可能会迷路。没有确认、重传或超时的概念。

未排序 – 如果两条消息发送给同一收件人,则无法预测它们到达的顺序。

轻量级 – 没有消息排序,没有跟踪连接等。它是一个设计在 IP 之上的小型传输层。

数据报 – 数据包单独发送,并且仅在数据包到达时检查其完整性。数据包具有明确的边界,在接收时会遵守这些边界,这意味着接收方套接字上的读取操作将产生与最初发送时一样的完整消息。
无拥塞控制 – UDP 本身无法避免拥塞。拥塞控制措施必须在应用层实施。

广播 – 由于无连接,UDP 可以广播 – 发送的数据包可以被寻址,以便子网上的所有设备都可以接收。

多播——支持多播操作模式,单个数据报包可以自动路由,而不会重复发送给大量订阅者。

UDP 的应用

许多关键的互联网应用程序都使用 UDP,包括: 域名系统 (DNS),其中查询必须快速且仅包含单个请求和单个回复数据包、简单网络管理协议 (SNMP)、路由信息协议 (RIP) 和动态主机配置协议 (DHCP)。

语音和视频流量一般使用UDP传输。实时视频和音频流协议旨在处理偶尔丢失的数据包,因此仅会出现轻微的质量下降,而不是在重新传输丢失的数据包时出现大的延迟。由于 TCP 和 UDP 都在同一网络上运行,因此许多企业发现来自这些实时应用程序的 UDP 流量最近的增加阻碍了使用 TCP 的应用程序的性能,例如销售点、会计和数据库系统。当 TCP 检测到数据包丢失时,它将限制其数据速率使用。由于实时应用程序和业务应用程序对企业都很重要,因此某些人认为开发服务质量解决方案至关重要。

某些 VPN 系统(例如 OpenVPN)可能会使用 UDP,同时在应用程序级别实现可靠的连接和错误检查。

TCP :

Transmission Control Protocol is a connection-oriented protocol, which means that it requires handshaking to set up end-to-end communications. Once a connection is set up, user data may be sent bi-directionally over the connection.

Reliable – Strictly only at transport layer, TCP manages message acknowledgment, retransmission and timeout. Multiple attempts to deliver the message are made. If it gets lost along the way, the server will re-request the lost part. In TCP, there's either no missing data, or, in case of multiple timeouts, the connection is dropped. (This reliability however does not cover application layer, at which a separate acknowledgement flow control is still necessary)

Ordered – If two messages are sent over a connection in sequence, the first message will reach the receiving application first. When data segments arrive in the wrong order, TCP buffers delay the out-of-order data until all data can be properly re-ordered and delivered to the application.

Heavyweight – TCP requires three packets to set up a socket connection, before any user data can be sent. TCP handles reliability and congestion control.
Streaming – Data is read as a byte stream, no distinguishing indications are transmitted to signal message (segment) boundaries.

Applications of TCP

World Wide Web, email, remote administration, and file transfer rely on TCP.

UDP :

User Datagram Protocol is a simpler message-based connectionless protocol. Connectionless protocols do not set up a dedicated end-to-end connection. Communication is achieved by transmitting information in one direction from source to destination without verifying the readiness or state of the receiver.

Unreliable – When a UDP message is sent, it cannot be known if it will reach its destination; it could get lost along the way. There is no concept of acknowledgment, retransmission, or timeout.

Not ordered – If two messages are sent to the same recipient, the order in which they arrive cannot be predicted.

Lightweight – There is no ordering of messages, no tracking connections, etc. It is a small transport layer designed on top of IP.

Datagrams – Packets are sent individually and are checked for integrity only if they arrive. Packets have definite boundaries which are honored upon receipt, meaning a read operation at the receiver socket will yield an entire message as it was originally sent.
No congestion control – UDP itself does not avoid congestion. Congestion control measures must be implemented at the application level.

Broadcasts – being connectionless, UDP can broadcast - sent packets can be addressed to be receivable by all devices on the subnet.

Multicast – a multicast mode of operation is supported whereby a single datagram packet can be automatically routed without duplication to very large numbers of subscribers.

Applications of UDP

Numerous key Internet applications use UDP, including: the Domain Name System (DNS), where queries must be fast and only consist of a single request followed by a single reply packet, the Simple Network Management Protocol (SNMP), the Routing Information Protocol (RIP) and the Dynamic Host Configuration Protocol (DHCP).

Voice and video traffic is generally transmitted using UDP. Real-time video and audio streaming protocols are designed to handle occasional lost packets, so only slight degradation in quality occurs, rather than large delays if lost packets were retransmitted. Because both TCP and UDP run over the same network, many businesses are finding that a recent increase in UDP traffic from these real-time applications is hindering the performance of applications using TCP, such as point of sale, accounting, and database systems. When TCP detects packet loss, it will throttle back its data rate usage. Since both real-time and business applications are important to businesses, developing quality of service solutions is seen as crucial by some.

Some VPN systems such as OpenVPN may use UDP while implementing reliable connections and error checking at the application level.

別甾虛僞 2024-10-29 01:41:20

TCP是一种面向连接的协议,它通过交换机、路由器、代理等建立一条路径或一条虚拟连接,然后开始任何通信。存在诸如路由 djikstras 最短路径算法之类的各种机制来建立虚拟端到端连接。因此,它发现自己在浏览 HTML 和其他页面、进行支付和一般网络应用程序时被使用。

UDP 是一种无连接协议 - 它只有一个目的地,如果目的地尽可能好,节点就简单地传递它。因此,数据包无序到达、沿不同路径到达等情况很常见。因此,即时通讯工具和类似软件开发人员认为 UDP 是理想的解决方案。

在现实生活中,如果你想将数据扔到网络中,而不用担心到达所需的时间,则到达的顺序使用UDP。如果您在开始发送数据包之前想要一条可靠的路径,并且希望数据包具有相同的顺序和延迟,请使用 TCP - 我将使用 UDP 来发送 Torrent,使用 TCP 来发送 PayPal!

TCP is a connection oriented protocol, It establishes a path, or a virtual connection all the way through switches routers proxies etc and then starts any communication. Various mechanisms like routing djikstras shortest path algorithm exist to establish the virtual end to end connection. So it finds itself used while browsing HTML and other pages, making payments and web applications in general.

UDP is a connectionless protocol - it simply has a destination and nodes simply pass it along if it comes as best as they can. So packets arriving out of order, along various routes etc are common. So Instant messengers and similar software developers think UDP an ideal solution.

In real life if you want to throw data in the net, without worrying about time taken to reach, order of reaching use UDP. If you want a solid path before you start throwing packets, and want same order and latency for your data packets use TCP - I will use UDP for Torrents and TCP for PayPal!

温柔女人霸气范 2024-10-29 01:41:20

当您必须移动大量数据(> ~1 kB)并且需要传送所有数据时,TCP 是合适的。几乎所有在互联网上传输的数据都是通过 TCP 进行的 - HTTP、SMTP、BitTorrent、SSH 等都使用 TCP。

当您有可以承受丢失的小消息并且希望尽可能高效地发送它们时,UDP 是合适的。您可以承受丢失它们的原因之一是,如果它们丢失,您可以重新发送它们。互联网上的主要示例是 DNS - DNS 由一些小查询组成,例如“stackoverflow.com 的 IP 号码是多少?”,并且响应相应较小。计算机会进行大量此类查询,因此应该高效地进行查询,但如果它们在途中丢失,很容易超时并重新发送它们。

TCP is appropriate when you have to move a decent amount of data (> ~1 kB), and you require all of it to be delivered. Almost all data that moves across the internet does so via TCP - HTTP, SMTP, BitTorrent, SSH, etc, all use TCP.

UDP is appropriate when you have small messages which you can afford to lose, and would like to send them as efficiently as possible. One reason you might be able to afford to lose them is because you can re-send them if they get lost. The main example on the internet is DNS - DNS consists of small queries saying things like "what is the IP number for stackoverflow.com?", and the responses are correspondingly small. Computers make a lot of these queries, so they should be made efficiently, but if they get lost en route, it's easy to time out and re-send them.

眼藏柔 2024-10-29 01:41:20

TCP 保证数据包传送和顺序。当重建可执行文件等文件的数据时,顺序几乎与交付一样重要。UDP

不保证交付 NOR 顺序。数据包可以按任何顺序到达(或不到达!)。

TCP 的常见用途包括文件传输,其中数据包的完整性至关重要。语音/视频应用程序可以承受丢失一些数据的同时仍保持可接受的质量,因此通常使用 UDP。

TCP guarantees packet delivery AND order. Order is almost as important as the delivery in the first place when reconstructing data for files such as executables, etc.

UDP does not guarantee delivery NOR order. Packets can arrive (or not!) in any order.

Common uses for TCP include file transfer where the integrity of the packets is paramount. Voice/video applications can afford to lose some data while still maintaining acceptable quality, and so usually use UDP.

微凉 2024-10-29 01:41:20
  • TCP:将以有意义的顺序到达那里
  • UDP:上帝知道(也许)
  • TCP: will get there in meaningful order
  • UDP: god knows (maybe)
沉睡月亮 2024-10-29 01:41:20

对上面讨论有序交付的一些评论还有一个额外的想法……必须澄清的是,目标计算机可能会在线路上接收到无序的数据包,但目标处的 TCP 负责“重新排列无序的数据包”。 -排序数据”,然后将其传递到堆栈的上层。当您说 TCP 保证有序数据包传送时,这意味着它将以正确的顺序将数据包传送到堆栈的上层。

One additional thought on some of the comments above that talks about ordered delivery.... It must be clarified that the destination computer may receive packets out of order on the wire, but the TCP at the destination is responsible for "rearranging out-of-order data" before passing it on to the upper layers of the stack. When you say TCP guarantees ordered packet delivery, what that means is it will deliver packets in correct order to the upper layers of the stack.

吃兔兔 2024-10-29 01:41:20
SCTP vs TCP vs UDPServices/Features       SCTP        TCP       UDP
Connection-oriented                       yes         yes       no
Full duplex                               yes         yes       yes
Reliable data transfer                    yes         yes       no
Partial-reliable data transfer            optional    no        no
Ordered data delivery                     yes         yes       no
Unordered data delivery                   yes         no        yes
Flow control                              yes         yes       no
Congestion control                        yes         yes       no
ECN capable                               yes         yes       no
Selective ACKs                            yes         optional  no
Preservation of message boundaries        yes         no        yes
Path MTU discovery                        yes         yes       no
Application PDU fragmentation             yes         yes       no
Application PDU bundling                  yes         yes       no
Multistreaming                            yes         no        no
Multihoming                               yes         no        no
Protection against SYN flooding attacks   yes         no        n/a
Allows half-closed connections            no          yes       n/a
Reachability check                        yes         yes       no
Psuedo-header for checksum                no (vtags)  yes       yes
Time wait state                           vtags       4-tuple   n/a
SCTP vs TCP vs UDPServices/Features       SCTP        TCP       UDP
Connection-oriented                       yes         yes       no
Full duplex                               yes         yes       yes
Reliable data transfer                    yes         yes       no
Partial-reliable data transfer            optional    no        no
Ordered data delivery                     yes         yes       no
Unordered data delivery                   yes         no        yes
Flow control                              yes         yes       no
Congestion control                        yes         yes       no
ECN capable                               yes         yes       no
Selective ACKs                            yes         optional  no
Preservation of message boundaries        yes         no        yes
Path MTU discovery                        yes         yes       no
Application PDU fragmentation             yes         yes       no
Application PDU bundling                  yes         yes       no
Multistreaming                            yes         no        no
Multihoming                               yes         no        no
Protection against SYN flooding attacks   yes         no        n/a
Allows half-closed connections            no          yes       n/a
Reachability check                        yes         yes       no
Psuedo-header for checksum                no (vtags)  yes       yes
Time wait state                           vtags       4-tuple   n/a
滥情稳全场 2024-10-29 01:41:20

由于 tcp 用法从其他答案中非常简单,我将提到一些有趣的 UDP 用例:

1)DHCP - 动态主机配置协议,用于动态分配 IP 地址和一些其他网络配置到连接设备。简单来说,该协议允许您只需连接到网线(或wifi)并开始使用互联网,无需任何额外的配置。 DHCP 使用 UDP 协议。由于设置请求消息是从主机广播的,并且无法与 DHCP 服务器建立 TCP 连接(您不知道它的地址),因此不可能使用 TCP 代替。

2)Traceroute - 著名的网络诊断工具,它允许您探索网络中数据报通过哪条路径到达目的地(以及需要多少时间)。默认情况下,它的工作原理是向目标发送不太可能的目标端口号(范围从 33434 到 33534)的 UDP 数据报,并将 ttl(生存时间)字段设置为 1。当网络中某处的路由器收到此类数据报时 -它发现数据报已过期。然后,路由器丢弃数据报并向数据报的源发送一条 ICMP(互联网控制消息协议)错误消息,指示数据报的 ttl 已过期并包含路由器的名称和 IP 地址。每次主机发送具有越来越高的 TTL 的数据报,从而增加它成功克服的网络部分并从新路由器获取新的 ICMP 消息。当它最终到达目的地时(数据报 TTL 足够大以允许它),- 目的地主机将“目的地端口无法到达”ICMP 消息发送到源主机。这样,Traceroute 就知道目的地已到达。由于 TCP 保证分段传送,因此使用 TCP 代替 UDP 至少效率低下,而 UDP 反过来又允许数据报被丢弃而无需任何重新发送尝试(重新发送是在更高级别上实现的,如上所述,不断增加 TTL) 。

Since tcp usages are pretty straightforward from other answers, I'll mention some interesting UDP use-cases:

1)DHCP - Dynamic Host Configuration Protocol, which is being used in order to dynamically assign IP address and some other network configuration to the connecting devices. In simple words, this protocol allows you just connect to the network cable(or wifi) and start using the internet, without any additional configurations. DHCP uses UDP protocol. Since the settings request message is being broadcasted from the host and there is no way to establish a TCP connection with DHCP server(you don't know it's address) it's impossible to use TCP instead.

2)Traceroute - well-known network diagnostic tool which allows you to explore which path in the network your datagram passes to reach it's destination(and how much time it takes). By default, it works by sending UDP datagram with unlikely destination port number(ranging from 33434 to 33534) to the destination with the ttl(time-to-live) field set to 1. When the router somewhere in the network gets such datagram - it finds out that the datagram is expired. Then, the router drops the datagram and sends to the origin of the datagram an ICMP(Internet Control Message Protocol) error message indicating that the datagram's ttl was expired and containing router's name and IP address. Each time the host sends datagrams with higher and higher TTL, thus increasing the network part which it succeeds to overcome and getting new ICMP messages from new routers. When it eventually reaches it's destination(datagrams TTL is big enough to allow it),- the destination host sends 'Destination port unreachable' ICMP message to the origin host. This way, Traceroute knows that the destination was reached. Since the TCP guarantees segments delivery it would be at least inefficient to use it instead of UDP which, in turn, allows datagram to be just dropped without any resend attempts(resend is implemented on the higher level, with continuously increasing TTL as described above).

浊酒尽余欢 2024-10-29 01:41:20

UDP 在游戏或其他点对点设置中被大量应用,因为它速度更快,并且大多数时候您不需要协议本身来确保所有内容都按原始顺序到达目的地(UDP 不保证数据包传递或交货单)。

另一方面,Web 流量是通过 TCP 传输的。 (我在这里不确定,但我认为这与 HTTP 协议的构建方式有关)

已编辑,因为我在 UDP 方面失败了。

UDP is applied a lot in games or other Peer-to-peer setups because it's faster and most of the time you don't need the protocol itself to make sure everything gets to the destination in the original order (UDP does not garantee packet delivery or delivery order).

Web traffic on the other hand is over TCP. (I'm not sure here but I think it has to do with the way the HTTP protocol is built)

Edited because I failed at UDP.

自由范儿 2024-10-29 01:41:20

TCP 和 UDP 的现实生活示例
TCP->电话、短信或任何特定于目的地的信息
UDP-> FM 广播频道 (AM)、Wi-Fi。

Real life examples of both TCP and UDP
tcp -> a phone call, sms or anything specific to destination
UDP -> a FM radio channel (AM), Wi-Fi.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文