Have you ever wondered how the internet works? How can you send and receive pictures, emails, calls and view websites from your internet-connected device from the comfort of your own home? These actions depend on TCP and UDP ports. How do these ports work and what are they?
Before delving into the topic, you need to understand what a port is. Computers use ports to communicate and connect to other computers on a network. The port in question here is not a physical component, but a virtual endpoint between two or more computers. The most common ports on the Internet are the TCP and UDP ports.
What are TCP ports?
TCP stands for Transmission Control Protocol and is a connection-oriented protocol. In networks, protocols are rules or standards that govern how data is transmitted between devices. TCP is called a connection-oriented protocol because it establishes a connection between the receiving and sending devices before transmitting data.
TCP ports are ports that conform to transmission control protocols. Some TCP ports include File Transfer Protocol ports (20 and 21) for file transfers, SMTP port (25) and IMAP port (143) for email, and Secure Shell port (22).
How do TCP ports work?
TCP ports create connections before releasing data. For example, if you want to tell your friend about a new movie or game, you can call them. You dial your friend’s number and when she answers and confirms you’re on the other end of the line, she picks it up. Then you can start telling her about the game.
This is how TCP ports work too. A secure connection between the sender and receiver device is ensured before the data is transferred. But how do devices using the TCP ports to receive or send data make this connection in the first place? You do this with the three-way handshake.
What is a three-way handshake?
With TCP, the device sending the data connects to the device that is supposed to receive it. The way TCP ports establish reliable connections is called a three-way handshake.
As the name suggests, a three-way handshake requires three different interactions, which take the form of three messages: SYN→SYN-ACK→ACK.
The first is the SYN segment. The sending device sends out a SYN (Synchronized Sequence Number) message to try to communicate with the receiving computer. It’s trying to say, “Hello! Are you available to connect?”
If the receiving device is available to establish a connection, it responds to the device sending the connection request with a SYN-ACK segment. The SYN-ACK segment acknowledges the connection request and returns a synchronized sequence number. In plain language, the device says: “Yes, I confirm your request and I’m ready to connect.”
In this case, the sending device sends an ACK segment to the receiving device, telling it that it has acknowledged its message. Then a connection is established and it starts transferring data. When the data transfer is confirmed and completed, the connection is terminated.
This way, all data sent to the receiving device will be sent complete and in the right order. Also, there are no missing packets because a connection was established first.
What are UDP ports?
UDP stands for User Datagram Protocol. The User Datagram Protocol is connectionless, which means that a host device can transmit data to its receiver without first establishing a connection. UDP ports depend on the UDP/IP protocols. UDP ports include the DNS port (53), the Dynamic Host Configuration Protocol port (68), and the Kerberos port (88) used by gaming services.
How do UDP ports work?
Unlike TCP ports, UDP ports do not need to establish connections before transmitting data. So if you wanted to tell your friend about a new movie imitating the Upport, you’d have to shout out your conversation and hope your friend is around and can hear you. Pretty unreliable, right?
Responsibility for obtaining the information you attempt to share rests solely with your friend. Since you haven’t established a connection yet, your friend may not hear you properly and may only hear fragments or nothing at all.
With UDP ports, the host sends data in packets (small segments) with no specific destination. It then hopes that the receiving device will get those packets, which is unreliable as it doesn’t guarantee that the data will be received seamlessly. As a result, packets do not get to the recipient and data is lost. This is known as packet loss.
What is the difference between TCP and UDP ports?
Although TCP ports perform the same function of sending information over the Internet, they have different functions and uses.
A TCP port is more reliable for communication and data transfer because, as a connection-oriented protocol, it establishes a connection between the two devices using a three-way handshake before sending data. In this way, all data arrives in the correct order. And if there is an error in the process, it is easy to spot. However, this is not the same with UDP ports.
Because of their reliability, TCP ports are used for services where you need secure and complete data transmission like emails, images, websites, etc.
Because UDP ports are connectionless protocols, they save a lot of time by not establishing connections before sending data packets, which is handy for time-sensitive services where data is received in real-time. UDP ports are used in video, voice, and game streaming.
TCP and UDP ports, explained
TCP and UDP ports are networking terms you don’t hear regularly, but they are the bedrock of our internet. These two ports play a huge role in your daily life as without these ports data transfer would be almost impossible.
This article was previously published on Source link