My router has two protocols (and a "both" option) that I can select when setting up port forwarding: UDP and TCP. What is the difference between these two protocols and when would you select one over the other in port forwarding?
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.
You can find a good summary here:
Both TCP and UDP work at transport layer TCP/IP model, but have very different usage.
The most important differences are:
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
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.
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:
An this the UDP frame structure, much simpler:
Typical protocols which use TCP are HTTP, FTP and SMTP. Examples of protocols using UDP are DNS and DHCP.
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.
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.
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.
As well as differences mentioned so far TCP also provides
flow control. Using a window mechanism the recipient limits how many octets (bytes) it wants to receive from the sender before the sender must wait for permission to send more data. The size of the window can be changed by the receiver as the conversation proceeds. This allows a receiver to 'throttle' the rate of data coming from a sender: UDP does not allow this and all a receiver can do is throw away data it cannot buffer or process on arrival.
some more technical facilities such as non-contiguous acknowledgement (uses selective acknowledgements to allow the sender to retransmit just a missing frame rather than the missing frame and subsequent ones that the receiver already has but could not acknowledge in the usual way), congestion handling and adaptive retransmission (adjusting the timer that decides how soon to resend a transmitted frame when an acknowledgement is not received). These are not relevant to UDP but help TCP to provide extra services over UDP without greatly increasing the network load for the same payload volume.
TCP makes an effort to ensure the data made it to the recipient; UDP does not.
Never mind all the answers explaining one vs. the the other. For the purposes of setting up a port-forward, the rules are pretty simple: you need to choose TCP, unless the docs for the protocol/application you're using say to use UDP. Usually the ones that use UDP are related to streaming, or very simple things that favour lightweight protocols/speed over reliability (particularly DNS and NTP). Note that there are other protocols besides TCP and UDP too -- ICMP, tunneling protocols, etc.
The more wellknowned a protocol is, the more routers on the path intervenes with the protocol. Send tcp packets, and there's a big probability the received packets are highly mangled. UDP is usually not that mangled, and the other 254 IP paylod protocols are usually completely untouched.
User Datagram Protocol (UDP)
It is part of the base protocols of the Internet Protocol Suite. Programs on networked computers can send short messages sometimes called as datagrams. UDP does not guarantee any reliability( it happens datagram may arrive out of order, are duplicated, or are missing without any notice). The fact that no checking whether all packets are actually delivered is made, UDP proves to be faster and more efficient, for applications that do not need guaranteed delivery. UDP find its uses in such situations:
Time-sensitive applications. The problems due to delayed packets are avoided
It is also useful for servers that answer small queries from huge numbers of clients. UDP supports packet broadcast (conveys to all on local network) and multicasting (conveys to all subscribers).
Transmission Control Protocol (TCP)
It is often referred to as TCP/IP due to the importance of this protocol in the Internet Protocol Suite. TCP operates at a higher level, concerned only with the two end systems, (e.g. between web browser and a web server). TCP provides reliable, sequential delivery of a stream of data from one program on one computer to another program on another computer. Common uses of TCP regroup e-mailing support and file transfer and Web applications. Among its management tasks, TCP controls message size, the rate at which messages are exchanged, and network traffic congestion. As for IP, it handles lower-level transmissions from computer to computer as a message transferred across the Internet.
Well both are network protocols built on top of something called Internet Protocol or IP. The Internet Protocol is the major protocol of the Internet and is for example what allows us to browse the web. That's why you will often see these protocols written as TCP/IP or UDP/IP. They are actually core protocols of the internet.
In both cases your data is split up into chunks called packets. TCP ensures that these packets get to their destination and in the correct order and without any errors.
UDP on other hand will not ensure that a data packet will even arrive. It will only ensure that if it does arrive it will be without error.
Typically, other protocols will run on top of TCP and UDP and are known as application protocols because they operate within an application and not within the operating system. Your web browse uses HTTP protocol which will use the TCP protocol.
Domain name lookups or DNS queries often use UDP but can also use TCP. A number of streaming services use UDP beneath another application protocols.
I hope that answers your question in simpler english.