So let us see in this slide
So port numbers are actually integer values between 0 to
65,535 and some range of these port numbers are actually reserved
Port numbers helps the operating system of receiving machine to identify the process to deliver the packet to
a process running on the machine if register a port number say
60,00 1 for example all packets which have
6 0001 as destination port number in their TCP or UDP header
Will be delivered to this process by the transport layer
so you can see that port number is actually identifies the application which is interested in receiving the packet and
Those packets which have destination port number as 60,00 1
will be delivered to the application which is actually
Listening on port number sixty thousand one
The application has to tell the operating system that hey I am interested in receiving all the TCP or UDP
Packets which are coming with destination port number blah blah blah
so let us take an example here that we have a source machine s and
We have a source machine D. Sorry destination machine D
on the source machine S
We are running three applications APP1 APP 2 and APP 3
App 1 is listening on port number 50,001 app 2 is listening on port number 50,002
And APP 3 is listening on port number fifty thousand three
Similarly APP 4 APP 5 and app-6 are listening on port number 6 0001, 6 0002 and 6 0003 respectively
Now suppose APP1 wants to send a data to APP 5
Right now for the app 1 to send a data to APP5
What should be present in the TCP header
That is what should be the source port number and destination port number specified by the app 1
in the TCP header
So in the TCP header or UDP header the app1 has to specify the source port number as
50001 and
the destination port number as 60,002
Right!! so this will complete the transport layer header
In the IP header the application 1 has to specify
the IP address of machine S
Which could be the IP address of any local interface
but again, it's a good practice to specify the IP address of a loopback interface of machine S
The APP 1 also has to specify the IP address of the destination machine
So this completes the IP header
So if the app 1 wants to communicate with the App 5
The App 1 has to specify the port numbers as well as the IP address
Then only the end-to-end communication between the source
Application that is app 1 and the destination application that is the App 5 is possible
So while the IP layer use this information to take the packet from source machine S to destination machine D
Once the packet arrives on the destination machine D the transport layer on the destination machine D
uses the information that is encoded in the
transport header
To deliver the packet to the correct application, which is interested in this packet
Now when this packet is received on destination machine D
the transport layer will check the destination port number in the packet and
It finds that the destination port number in the packet is 60,002
so it will check that what are those applications which are listening on port number 6 0002
So the operating system will find that the app 5 is the machine which is listening on port number 60002
So the packet will be delivered to application 5
Remember there could be more than one applications which are registered or which are listening to the same port number
If that is the case the transport layer will going to handover the packet to all those relevant
applications which are
Interested in receiving that particular packet based on port number they are listening
Now
so if process that is APP 2 running on machine S wants to send data to any process that
Is APP 5 running on machine D
That is app 2 running on source machine s wants to send data to
application 5 running on destination machine D
Application 2 needs needs to specify the following information
That is application 5 host machine IP address. host machine means the machine on which application 5 is running
So the app 2 needs to know these IP address
APP2 also needs to know the port number on which application 5 is listening. So in this case 60,002
Right!! so these two pieces of information that is the IP address of the destination machine and the port number of the application
which is
Interested in receiving the packet. these two information the source application APP2 to needs to know
Rest of the information required to deliver the packet is gathered by the operating system by sending
Is gathered by the operating system of sending machine that is operating system of machine s or intermediate machine
Such as TCP sequence number or source and destination MAC addresses, etc
So as an end user or as a programmer
You need not to find the source and destination MAC addresses because source and destination MAC addresses keeps on changing
Hope by hope so the operating system
does it by itself using ARP table and ARP broadcast request and all that stuff
As an end user
you need to specify the destination machines IP address and the port number of the
Application running on destination machine if you know these two information
Then you can set up end to end communication between the two applications