TCP and UDP Ports Explained

Here we will discuss the concept of ports and how they work with IP addresses.You need to be clear with concept of IP addresses.

The devices and the computers which are connected to the internet communicate with each other using TCP/IP protocols.Whenever a computer needs to send some kind of information to another computer then it needs to know the destination ie the IP address where the information needs to be directed to.That information is sent most
often via two methods, UDP and TCP.

The two Internet workhorses: UDP and TCP

UDP? TCP?Confusing? Well I will try to remove this confusion.

TCP stands for Transmission Control Protocol.

Using this method, the computer sending the data connects directly to the computer it is sending the data it to, and stays connected for the duration of the transfer. With this method, the two computers can guarantee that the data has arrived safely and correctly, and then they disconnect the connection. This method of transferring data tends to be quicker and more reliable, but puts a higher load on the computer as it has to monitor the connection and the data going across it

UDP stands for User Datagram Protocol.

Using this method, the computer sending the data packages the
information into a nice little package and releases it into the network with the hopes that it will get to the right place. What this means is that UDP does not connect directly to the receiving computer like TCP does, but rather sends the data out and relies on the devices in between the sending computer and the receiving computer to get the data where it is supposed to go properly. This method of transmission does not provide
any guarantee that the data you send will ever reach its destination.

Real life analogy of TCP and UDP…

TCP-A real life comparison to this method would be to pick up the phone and call a friend. You have a conversation and when it is over, you both hang up, releasing the connection.

UDP-Its like the postal service where we place the data hoping that it would reach the destination correctly but sometimes it does not.

TCP and UDP Ports

The IP address of our machine is used for its recognition in the internet.Whenever an information is sent for my IP address then it accepts the information via the TCP or UDP ports.

An easy way to understand ports is to imagine your IP address is a cable box and the ports are the different channels on that cable box. The cable company knows how to send cable to your cable box based upon a unique serial number associated with that box (IP Address), and then you receive the individual shows on different channels (Ports).

Ports work the same way. You have an IP address, and then many ports on that IP address. When I say many, We can have a total of 65,535 TCP Ports and another 65,535 UDP ports. When a program on your computer sends or receives data over the Internet it sends that data to an ip address and a specific  port on the remote computer, and receives the data on a usually random port on its own computer. If it uses the TCP protocol to send and receive the data then it will connect and bind itself to a TCP port. If it uses the UDP protocol to send and receive data, it will use a UDP port.

Figure 1, below, is a representation of an IP address split into its many TCP and UDP ports. Note that once an application binds itself to a particular port, that port can not be used by any other application. It is first come, first served.

<——————– 192.168.1.10 ——————–>

0 1 2 3 4 5 .. .. .. .. .. .. .. .. 65531 65532 65533 65534 65535

Figure 1. IP address with Ports 

In order for a web server to accept connections from remote computers  it must bind the web server application to a local port. It will then use this port to listen for and accept connections from remote computers.

Web servers typically bind to the TCP port 80, which is what the http protocol uses by default, and then will wait and listen for connections from remote devices.

Once a device is connected, it will send the requested web pages to the remote device, and when done disconnect the connection.

On the other hand, if you are the remote user connecting to a web server it would work in reverse.

The web browser would pick a random TCP port from a certain range of port numbers, and attempt to connect to port 80 on the IP address of the web server. When the connection is established, the web browser will send the request for a particular web page and receive it from the web server.

Then both computers will disconnect the connection. Now, what if you wanted to run a FTP server, which is a server that allows you to transfer and receive files from remote computers, on the same web server.

FTP servers uses TCP ports 20 and 21 to send and receive  information, so you won’t have any conflicts with the web server running on TCP port 80.

Therefore, the FTP server application when it starts will bind itself to TCP ports 20 and 21, and wait for connections in order to send and receive data.

Most major applications have a specific port that they listen on and they register this information with an organization called IANA. A List of applications and the ports they used  at the IANA Registry can be easily seen.

With developers registering the ports their applications use with IANA, the chances of two programs attempting to use the same port, and therefore causing a conflict, will be diminished.

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s