开发者

What are examples of TCP and UDP in real life?

开发者 https://www.devze.com 2023-02-17 11:18 出处:网络
I know the difference between the two on a technical level. But in re开发者_高级运维al life, can anyone provide examples (the more the better) of applications (uses) of TCP and UDP to demonstrate the

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

But in re开发者_高级运维al life, can anyone provide examples (the more the better) of applications (uses) of TCP and UDP to demonstrate the difference?


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 :)


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.


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)


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.


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


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)


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.


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!


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.


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.


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.


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.


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


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).


  • TCP: will get there in meaningful order
  • UDP: god knows (maybe)


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消