What Are TCP and UDP?
TCP, which stands for Transmission Control Protocol, is a connection-oriented protocol that PCs use to communicate over the Internet. As one of the primary protocols in a TCP/IP network, its main purpose is to check for errors and guarantee data delivery. It ensures that the data packets will be transmitted in the order they were sent.
On the other hand, User Datagram Protocol—or UDP—is a connection-free protocol. It functions almost the same as TCP, but it does not require error-checking and recovery services. What it does is continuously deliver datagrams to the recipient. UDP keeps on doing this regardless of whether the delivery was successful or not.
What Is the Difference Between UDP and TCP?
TCP and UDP have many similarities. For one, they are both among the most popular protocols for delivering data packets over the Internet. Moreover, they use the IP protocol while working on the transport layer of the TCP/IP protocol stack. To give you a better understanding of how they function, let’s look at some of the key differences between the two:
Features in Data Transfer
TCP has been developed to reliably deliver a stream of bytes between a user and a server. In case data is lost during transit, TCP will recover it and resend it. In contrast, UDP does not share the same dedication to end-to-end communication and connections. Moreover, it does not check the receiver’s readiness. With UDP, there is no concept of retransmission, acknowledgement, and timeout.
Transmissions over TCP are delivered in a sequence. They are also received in the same sequence. If the data segments arrive in the wrong order, TCP will reorganize them before resuming delivery. With UDP, the delivered message sequence may not be maintained once it reaches the receiving application. No one can foresee the sequence in which the message will be received.
To ensure that a sender will not send too many packets at once, which may overwhelm a receiver, TCP puts a flow control mechanism in place. It has a ‘send buffer’ that stores data and a ‘receive buffer’ where it receives data. Once an application is ready, it will go to the receive buffer and read the data. Keep in mind that if TCP learns that the receive buffer is full, the receiver will drop the excess data.
Moreover, the receiver will tell the sender if there is enough room in the receive buffer, ensuring that the amount of data that can be delivered to the receiver is properly managed. Whenever the receiver gets a packet, the sender will get a message with the receive window’s current value.
If you want a lightweight connection, choose UDP over TCP. Its transport layer is designed over an IP, requiring no ordering of messages or tracking of connections. On the other hand, TCP needs three packets for a socket connection. Moreover, it requires more resources for reliability and handling congestion control. Of course, you can expect it to be slower than UDP because it lifts the heavier weight.
TCP uses byte streams to read data, and it transmits a message over segment boundaries. On the other hand, messages over UDP are individually sent via packets. These packets are checked upon arrival for their integrity. Unlike packets, a data stream has no defined boundaries.
While UDP’s protocol uses a checksum to support error detection, it discards a packet if it finds any error. It does not attempt to recover the packet and redeliver it. The reason behind this is because UDP is designed for time-sensitive applications like voice or gaming transmissions. It would be pointless to recover the packet. The packet won’t have any use by the time it is received after the retransmission.
Meanwhile, TCP enforces both error detection and recovery. It uses a checksum to identify errors, and if it finds any problematic packet, the receiver does not acknowledge it. This signals the sender to redeliver the packet via an operating mechanism referred to as ‘Positive Acknowledgement with Retransmission’ (PAR).
What Are the Applications of UDP and TCP?
TCP is mostly used for file transfer, web browsing, and email exchange. It plays a crucial role in managing network congestion, flow control, data exchange rate, and segment size. If error detection and correction is necessary at the network-interface level, TCP is usually the ideal solution.
On the other hand, UDP is preferred for time-sensitive applications and for servers that accommodate small but multiple queries from several clients. It is perfect for packet broadcasting that requires delivering and multicasting data to everyone on a network. UDP is usually used in online games, Domain Name Systems, Voice over IP, and Trivial File Transfer Protocols.
TCP vs. UDP: Which Is Better for OpenVPN?
It is worth noting that OpenVPN can run on both TCP and UDP ports. Selecting which one to use is a highly technical matter. So, most of the time, VPN providers keep the information private. However, there are some VPNs that let the subscribers choose their preferred connection protocol. Selecting TCP or UDP can be challenging, especially since both provide distinct advantages and disadvantages, depending on the Internet connection’s application. Ultimately, it all boils down to what’s important to the consumer—speed or reliability. Here is a quick breakdown of the two protocols:
- More Reliable – VPN services that use TCP for OpenVPN provide more stable connections since the protocol guarantees packet delivery.
- Effective in Bypassing Firewalls – In most cases, TCP VPN tunnels are not blocked, especially because they run on common ports (80 and 443). Most of the time, you can expect the tunnels to bypass even corporate firewalls.
- Slower Connections – Since TCP uses higher encryption methods, it tends to deliver slower transfer rates. If you want higher transfer rates for OpenVPN, UDP is the best solution.
- Faster Connections – Compared to TCP, VPN services using UDP provide significantly faster speeds. This is also the reason why it is the ideal protocol for downloading torrents, playing online games, or streaming HD videos.
- Preferred by Many – Networks that support UDP VPN tunnels prefer this OpenVPN connection method.
- Less Reliable – UDP is not as reliable as TCP VPN connections. After all, it does not guarantee packet delivery.
Using TCP Port 443 on OpenVPN for Bypassing Censorship
SSL encryption protects your connection whenever you try to access a secure website. You can tell which websites are secure by looking at the URL or web address. Usually, they start with https: and they feature a closed lock icon on the URL bar. Before, financial websites and online shops were the ones to heavily incorporate SSL encryption. However, because of the growing concern over Internet security, it is not uncommon to find websites from different industries deploying this security protocol.
What’s interesting about OpenVPN is it is designed to run on TCP port 443. The protocol, which is based on Open SSL libraries, generates traffic that seems similar to SSL connections. So, for bypassing censorship, running OpenVPN over TCP port 443 will bring success. After all, blocking SSL protocols effectively means breaking the Internet—which is virtually impossible.
TCP or UDP: Which Is Ideal for Game Servers?
When it comes to choosing between UDP or TCP connections for massively multiplayer online (MMO) games, developers usually make a decision for architectural reasons. TCP is more reliable, especially since it has the ability to use packets with arbitrary sizes. However, issues arise from its algorithm for congestion control. TCP treats packet loss as an indicator of bandwidth limitations, automatically throttling the packet delivery. So, over Wi-Fi or 3G networks, this problem can cause significant latency.
If you cannot decide over UDP and TCP, check the following criteria:
- For occasional, stateless, and client-initiated queries, use HTTP over TCP, especially in instances wherein slight delays are acceptable.
- If both the server and client send packets independently and an occasional delay is acceptable, use persistent plain TCP sockets.
- If both the server and client deliver packets independently and occasional lag is unacceptable, use UDP.
If you want to determine which is the better option for you, you have to ask yourself whether reliability or speed is your primary concern. Generally, UDP is preferred for playing games online and for streaming VoIP. That said, TCP connections can slow down, depending on various network factors, including distance. If you are geographically located far from the VPN server, the TCP packets have to travel further.
So, your connection will be slower. Now, if the server is relatively close to you, you may not notice any speed loss. As such, you will still have a fast and reliable connection. Our best advice is to use UDP for OpenVPN to get faster connections. By default, this is what most VPN providers use anyway.