What is the difference between UDP and TCP?

Solution 1:

You can find a good summary here:

What is the difference between UDP and TCP internet protocols?

Both TCP and UDP work at transport layer TCP/IP model, but have very different usage.

The most important differences are:

  • Reliability:
    TCP: connection-oriented
    UDP: connectionless
  • Ordered:
    TCP: order of message receipt is guaranteed
    UDP: order is not guaranteed
  • Protocol weight:
    TCP: heavyweight, because of the connection/ordering overhead
    UDP: lightweight, very few overhead
  • Packets:
    TCP: streaming, data is read as a "stream," with nothing distinguishing where one packet ends and another begins. There may be multiple packets per read call.
    UDP: datagrams, one packet per one read call.

Frame structure

When data is sent over the network, it needs to be encapsulated into so called "frames." There are various methods of encapsulation depending on the protocol and topology that are being used. The following images show how TCP and UDP frame structures differ.

This is the TCP frame structure:

TCP frame

An this the UDP frame structure, much simpler:

UDP frame

Typical protocols which use TCP are HTTP, FTP and SMTP. Examples of protocols using UDP are DNS and DHCP.

Solution 2:

TCP is backed by acks and retries to make sure you data gets where it's going. UDP is connectionless and "fire and forget". UDP is mostly used for streaming type applications, where if you lose some data you don't need to try to send it again.

Which one you use depends on the application. For example, a web server uses TCP.


Solution 3:

And the CEO level explanation:

UDP is when you throw your paper in the general direction of the bin.

TCP is when it misses, you throw exact copies of the same paper again and again until it falls into the bin. There would be paper wastage, even resent TCP packets result in wastage of network or system resources.


Solution 4:

TCP and UDP are both protocols that run on top of IP. TCP has guaranteed delivery and UDP does not. You would select one or the other for port forwarding depending on what service you're trying to forward. HTTP, for instance is TCP. If you don't know what protocol the service you're trying to forward is, it's almost certainly TCP.


Solution 5:

To answer other part of your question, you have to forward what your application uses. To forward HTTP traffic, select TCP. To forward TFTP traffic, select UDP. p2p programs mostly use both tcp and udp, so forward them both.

It all depends on the protocol and the program you are using.