TCP or UDP Protocol, Which is Better?

Simon Kim
6 min readNov 15, 2019

--

Computer Network (pixabay.com)

With computer networks, just like in humans, there must be rules in order for any meaningful communication to take place. There are several assumptions to these rules. Failure to follow them, communication fails. Example.

Both parties must understand the language of communication.

One party must talk while the other party is listening, that is they cannot talk at the same time.

There must be reasonable speed of talking so that the listener gets the meaning without repetition by the speaker.

The listener in most cases is expected to respond or acknowledge that he understands what is being said.

The above are implied protocols of a successful communication between humans.

In computer networks such rules are called Protocols.

Computer Protocols are set of rules that govern communication between networking devices. This include desktop to desktop, desktop to routers, routers to switches, switches to firewalls, and many others.

In this article, we are going to compare two Protocols (rules), TCP and UDP protocols, how they work, and which one is suitable for what situation.

TCP Protocol

TCP stands for Transmission Control Protocol.

How does it work? TCP protocol is a connection-oriented protocol, meaning it must first establish a virtual link between the devices before any information exchange takes place.

In order for you to understand this mode of connection, let us use a simple analogy of a telephone communication between two individuals.

To establish a telephone call, a caller places a call by dialing the correct number of the recipient.

Receiver picks the call thereby establishing a link between them. Usually they test the link by exchanging the words such as “Hello!” or “Hi!”.

If they can hear each other, they can go further and start having a conversation, but if they cannot hear each other the call is disconnected. Also, if one is using a language that the other cannot understand, the call is disconnected. If, the caller expected to hear a different person speaking, he must have dialed a wrong number, the call is disconnected too.

Sometimes if the caller cannot hear the recipient, he disconnects the call and either calls back again or waits for a call back.

That is the way the cell(tele)phone system works.

TCP establishes a link first (phone analogy)

TCP protocol works in a similar manner. It establishes a link first and then data is exchanged. In the computer networks, this is called a Connection Oriented Protocol.

Connection Oriented services does not happen without first establishing a connection between the two devices.

In a very simplified way, there are three steps that are followed while using TCP Protocol. These are;

a) A connection must be established first

b) Next, Data is transmitted

c) Connection is released

What are the advantages of using TCP Protocol?

Reliability

TCP ensures that data sent is delivered. It guarantees that the receiver gets it by re-sending any lost packets. TCP checks data packets for errors. This makes it a reliable protocol.

Flow control

TCP has a flow control way that makes sure the receiver of data is not overwhelmed by too many packets at ago. It has two buffers, namely send buffer and receive buffer. Data is stored in these buffers. Before sending, receive buffer informs the TCP if the receiver would be able to accommodate more data or not. When the receive buffer is full, it means that the receiver would not be able to hold more data and would drop it. To ensure the correct amount of data is being sent, a receiver informs the sender how much extra space it has in receive buffer or window. Each time a packet is received, a message is sent back to the sender showing the current value of receive window.

Ordering

TCP is meticulous in maintaining order in which packets are sent and arrive. The packets are sequenced and TCP ensures that they arrive in a similar order they were transmitted from the server to the client.

Speed

TCP is slower compared to UDP, since it has quite a lot to do before data is exchanged. For example, it has to establish a link, check data for errors, ensure order and sequence on both ends.

Application of a TCP Protocol

TCP is used in applications that need high reliability but where speed is not a big issue. These areas may include the following:

· World Wide Web (HTTP, HTTPS)

· Email (SMTP, IMAP/POP)

· Telnet

· Secure Shell (SSH)

· File Transfer Protocol (FTP)

TCP Protocol Summary

TCP

Reliable — guarantee delivery

Byte stream — in-order delivery

Connection-oriented — single socket per connection

Setup connection followed by data transfer

Analogy — Telephone Call

Guaranteed delivery

In-order delivery

Connection-oriented

Setup connection followed by conversation

UDP Protocol

UDP Stands for User Datagram Protocol.

How does it work?

UDP is a connection-less protocol, meaning, it does not need to establish any connection with its communicating counterpart device before exchanging data.

Analogy of a postal office services will help you understand better they way connection-less services work.

In post office, a single mail box receive all the letters. Although all the letters have correct address, there is no guarantee of delivery, it is unreliable. Second letter can arrive before the first letter, therefore there is no order of delivery. Letters are sent independently. You must address each reply.

Connection-less (post office analogy)

The UDP protocol employs connection-less service like a post office.

It uses a single socket to receive messages (single mail box). It does not guarantee delivery of messages. Data packets can arrive in disarray without any order at all. Datagram are sent independently, and each packet must be addressed.

One similarity between TCP and UDP is that, they both work in a Transport layer of TCP/IP protocol stack. They both use IP protocol.

Reliability

UDP does not do any error-checking and recovery services. It just sends the datagrams continuously to the recipient. Whether they arrive or not, it does not matter, no way of verifying that. UDP is unreliable. There is no guaranteed delivery. Datagram packet may get lost or corrupted in transit.

Flow Control

There is no flow control in UDP. Packets arrive in a continuous stream or lost.

Ordering

With UDP, there is no sequencing or ordering. UDP send data packets in any order and arrive in no particular order.

Speed

Since UDP, does not have to establish a link first before sending data packets, does not do error-checking, of flow controls, it is far much faster than TCP.

Application of UDP

UDP is mainly used in applications that efficiency and speed are critical. It is used in the following areas;

· Domain Name System (DNS)

· Online games

· Voice over Internet Protocol (VoIP)

· Live broadcasts

· VPN tunnelling

· Streaming videos

· Trivial File Transfer Protocol (TFTP)

· Multimedia

Summary for UDP

UDP Protocol

Single socket to receive messages

No guarantee of delivery

Not necessarily in-order delivery

Datagram — independent packets

Must address each packet

Analogy — Post office

Single mailbox to receive letters

Unreliable

Not necessarily in-order delivery

Letters sent independently

Must address each reply

Depending on your needs, now you can make an informed decision which of the above protocols to use. There is no better protocol than the other. It depends on what you want to achieve.

For reliability, flow control, order and error checking, then TCP is your best bet. Need speed and efficiency? Then UDP will foot the bill.

--

--

Simon Kim
Simon Kim

No responses yet