You may have encountered TCP and UDP while setting up port forwarding on the router or while configuring firewall software; But do you know what these two protocols are and what the differences are?
TCP and UDP are two protocols used for different types of data. Devices and computers connected to the Internet using a protocol called TCP / IP to communicate with each other. TCP / IP is a set of protocols used by devices to communicate over the Internet and most local area networks. The name TCP / IP is derived from two main protocols: Transmission Control Protocol (TCP) and Internet Protocol (IP).
TCP provides applications with a way to deliver and receive packets sorted and reviewed over the network. The User Datagram Protocol (UDP) is used by applications to provide faster data flow by eliminating error checking.
When configuring home network hardware or software, you may need to know the difference between the TCP and UDP protocols. TCP and UDP protocols to understand the differences and what each is, with Zvmyt Stay tuned.
Features of TCP and UDP protocols
When a computer in New York wants to send data to a computer in Tehran, it must know the IP address of the destination computer (the computer in Tehran). This information is often sent via UDP and TCP. TCP and UDP are protocols used to send bits of data or packets over the Internet. Both protocols are IP dependent; In other words, it does not matter if you send a packet via TCP or UDP, in any case, the packet will be sent to an IP address.
Using the Transfer Control Protocol (TCP), the data sender’s computer connects directly to the computer to which the data is being sent and stays there for as long as the transfer takes place. With the help of this method, these two computers can disconnect after ensuring the data entry is safe and correct. This method of data transfer is faster and more secure, But it puts more load on the computer because it has to control the connection and the data in it. For example, suppose you pick up the phone and call your friend; When both are done, you both hang up and release the connection.
Sent packets are tracked by TCP so no data is lost or corrupted during transmission; This is why downloading files will not be interrupted even if the network is down. However, if the receiver is completely offline, your computer will stop sending the packet and you will see an error message saying that it cannot communicate with the host. TCP achieves this in two ways:
- Order packages by numbering them
- Check for an error by sending a response from the recipient to the sender stating that he has received the message.
If the sender does not receive the correct response, it can resend the packets to make sure the recipient has received them correctly.
Process Explorer and other system processing tools can show the type of communication created by a process. In the image below, you can see the Chrome browser with open TCP connections to all types of web servers.
Using the User Datagram Protocol (UDP), the computer that sends the information stores the data in small packets and releases them over the network in the hope that they will reach their destination. This means that UDP, like TCP, does not connect directly to the receiving computer; Instead, it sends the data abroad and relies on devices between the sender’s computer and the receiver’s computer to receive the data at the intended destination.
This method of transfer does not guarantee that the transmitted data will reach its destination. On the other hand, this method of transmission has very little overhead; Therefore, its use is useful for services that do not care about the successful receipt and transmission of data on the first try.
A simple example of this is the use of older postal services; You put your letter in the mailbox and hope the postal service will get it to the right place.
This is done most of the time; But sometimes it gets lost along the way.
Data transfer using UDP is faster; Because the sender does not wait to make sure the recipient has received the package; But continues to send subsequent packages.
If the receiver loses several UDP packets, they are lost and the sender does not resend them. UDP is used when speed is the main criterion and error correction is not required. UDP is often used in live video broadcasts and online games.
For example, suppose you are watching a live video stream that is playing using UDP. The server only sends a steady stream of UDP packets to the viewer computer; So when your connection is lost for a few seconds, the video may pause or skip; But then it goes to the current bit.
If you miss a portion of the package, the video or audio will be distorted for a moment and the movie will continue playing without missing tracks.
This is what happens in online games. If you lose some UDP packages while playing, when you receive newer UDP packages, the game character appears to be teleported to the map.
In case of losing old packages, requesting to get them back is useless; Because the game goes on without you; All that matters is what is currently happening on the game server (not what happened a few seconds ago). Failure to correct the error in TCP will help speed up the game connection and reduce latency.
TCP or UDP port
Every computer or device on the Internet is identified by a unique number called an IP address. This address is used to identify your computer among millions of other computers connected to the Internet. When information is sent over the Internet, your computer receives this information using TCP or UDP ports.
- How to access the IP address of the system in Windows
You have one IP address and many ports in this IP address, and you can have a total of 65535 TCP ports and 65535 UDP ports. When a program on your computer receives or sends information over the Internet, it essentially sends the data to an IP address and a specific port on the destination computer and receives the data on a random port on your computer. The TCP protocol uses the TCP port to send and receive data, and the UDP protocol uses the UDP port to send and receive data. The image below is a representation of an IP address divided into several TCP and UDP ports. Note that no other program can use that port whenever it connects to a specific port.
Since this is a little difficult to understand, we will give you a simple example; In this example, we use web servers. You know that a web server is a computer that runs a program and allows other computers to connect to it and access web pages stored there.
For a webserver to accept a remote computer connection request, it must connect the web server application to a local port.
The web server then uses this port to listen and accept remote computer communication.
Web servers typically connect to port 80 TCP; The same port that the HTTP protocol uses by default and then waits for remote computers to connect. After a device is connected, it sends the requested web pages to the device remotely and disconnects when done.
On the other hand, if you are a remote user who wants to connect to a web server, the opposite is true; Your web browser selects a random TCP port from a specific range of port numbers and tries to connect to port 80 at the web server’s IP address. Once connected, the web browser sends the request to a specific web page and receives it from the webserver; After this, both computers will disconnect.
But how do you set up an FTP server (which allows you to transfer and download files from remote computers to the same webserver)? FTP servers use TCP 20 and TCP 21 ports to send and receive information, so you will not have any conflicts with the webserver running on the TCP 80 port. As a result, when the FTP server program is running, it connects to TCP 20 and TCP 21 ports and waits for the connection to send and receive data.
Use of protocols
Applications use TCP or UDP depending on their needs and the decision of their developers. Most programs require TCP error correction and stability, But some programs need to speed up and reduce UDP overhead. Unless you are a network administrator or software developer, this should not affect your business much.
With the help of a network analysis tool such as Wireshark, you can see the different types of packets that are being transmitted.
If you have configured your router or firewall software and you are not sure if an application is using TCP or UDP, you can simply select Both to have your router or firewall apply the same rule to TCP and UDP traffic.