-: Data Transfer Over Networks. 2 2
So, when we transfer data over our networks, 3 3
we have to find a way to tell the data where it's going to go. 4 4
Now, we use IP addresses to get data to the right system. 5 5
But how does it know what application 6 6
is listening on that particular system? 7 7
Well, that's where a port comes in. 8 8
I like to think about it this way, 9 9
if I give you my street address, 10 10
that's like my IP address. 11 11
You can find my exact house within my neighborhood. 12 12
But, how are you going to find my bedroom, 13 13
my home office, or my living room. 14 14
Each of those rooms is going to serve a different function, 15 15
like sleeping, working, or relaxing. 16 16
Well, this is where a port is going to come in. 17 17
A Port is a logical opening in a computer 18 18
that represents a service or application 19 19
that's listening and waiting for traffic. 20 20
So, in my house example, 21 21
maybe I gave you my address as 123 Main Street, 22 22
room number two. 23 23
This tells you to go to the house and enter the second room, 24 24
which is my home office where I might be working at. 25 25
Now, in computer networks, our ports are going to be numbered 26 26
from zero all the way up to 65,535. 27 27
That is a lot of ports. 28 28
So, even though you only have one IP on your machine, 29 29
you can have over 65,000 different openings 30 30
for you to be able to run different services 31 31
and applications on. 32 32
Now, that large number of ports is actually broken up 33 33
into two distinct groups. 34 34
The first is called the Well-known and Reserved Ports. 35 35
These are the ports that are numbered 36 36
from zero through a 1023. 37 37
These include things like the File Transfer Protocol 38 38
on port 21, Web Browsing on port 80, 39 39
or the Simple Mail Transfer Protocol on port 25, 40 40
among other things. 41 41
Ephemeral Ports, on the other hand, 42 42
are short-lived temporary ports. 43 43
And these are open for just a small period of time 44 44
from a predefined range of ports. 45 45
These ports can exist from Port 1024, 46 46
all the way up to 65,535. 47 47
For example, as I'm recording this lesson, 48 48
I record the audio on a device which acts a file server, 49 49
and it's going to pick a random port 50 50
somewhere around port 60,000. 51 51
Now, when I want to download the audio file from the device, 52 52
I'm going to use a web browser on my computer 53 53
to access it and download that audio file. 54 54
When I do that, what happened is that I just opened up 55 55
a port on the device for as long as it's needed 56 56
in order to download that file 57 57
and then the port is going to close up again, 58 58
just that quickly. 59 59
Now, data transfer occurs using these IP addresses 60 60
in these ports. 61 61
So, what does all this look like inside the real world? 62 62
Well, as you can see here, I have a Client on the left 63 63
and a Website on the right. 64 64
The Client is at the address 192.168.1.24, 65 65
and the Website is at 64.82.46.21. 66 66
So, for the client to make a request to this website, 67 67
it's going to come from the source IP, 68 68
that 192 address, and a port, 69 69
just some random high port that it's going to pick 70 70
from the Ephemeral port range. 71 71
Now, in this case, it shows port number 49,163, 72 72
but it could have been any Ephemeral port. 73 73
Now, we're going to take that data 74 74
and we're going to send it to the destination of the website, 75 75
which in this case is going to be the IP address 76 76
of 64. something that you see here on the web server. 77 77
This is going to act as our destination IP. 78 78
And what port do you think it's going to go to? 79 79
Well, it's going to use the default port for websites, 80 80
which is Port 80. 81 81
Now, the website, on the other hand 82 82
is going to reverse this process. 83 83
And it's going to go from its source IP 84 84
and its own port 80 back to the client 85 85
on its random high port, which was port 49,163. 86 86
So, you can see how this communication happens 87 87
to establish this session. 88 88
And then, they can communicate back and forth 89 89
between the two servers and the client over these two ports. 90 90
Whenever we're done transmitting this website, 91 91
that random high port that was opened on your client, 92 92
it's going to get closed and another random high port 93 93
will be opened the next time you need to communicate. 94 94
But back on the web server, 95 95
port 80 is going to sit there and always remain open 96 96
ready to serve requests from anybody 97 97
who wants to communicate with that website. 98 98
So, when we send the information across the network, 99 99
we're doing this as an IPv4 packet. 100 100
Now, IP version four packets consist of a source address, 101 101
that's the IP address of the sender, 102 102
a destination address, the IP address of the receiver, 103 103
the IP flags, which is going to allow the packet fragmentation 104 104
other special things to occur, 105 105
and the protocol, which is whether we're going to communicate 106 106
using TCP or UDP. 107 107
All of those things are going to make up this packet header 108 108
and you can see it shown here on the screen. 109 109
Now, many times students asked me 110 110
if they have to memorize this packet header for the exam. 111 111
Well, the answer is no, no, no, no, no, no. 112 112
You don't have to worry about it, 113 113
because no one is going to ask you to draw out 114 114
or diagram a packet for the exam. 115 115
That said, I do want you to understand that your header 116 116
contains a couple of key pieces of information. 117 117
Things like your source and destination IP, 118 118
as well as the ports and the protocols 119 119
and things of that nature. 120 120
This tells your packet where it needs to get routed to. 121 121
Now, back when we talked about TCP and UDP, 122 122
we talked about the fact that TCP had a lot more overhead. 123 123
But, what does that really look like 124 124
inside of these packets? 125 125
Well, that's what I have here on the screen. 126 126
On the top, you can see the TCP header, 127 127
which is 20 bytes in length. 128 128
And you can see some things that it contains, 129 129
like the Source Port and the Destination Port, 130 130
the Sequence Number, the Acknowledgement Number, 131 131
and then a bunch of other flags. 132 132
All of that with the Checksum and the Pointers, 133 133
it all adds this overall length, 134 134
making it a pretty bulky protocol. 135 135
Now, we can compare this TCP header with a UDP header 136 136
that's shown here on the bottom. 137 137
It only has four pieces of information. 138 138
It has a Source Port, a Destination Port, 139 139
the length of the packet and the Checksum. 140 140
That's it, and it's only eight bytes long. 141 141
So, you can see there's a lot less data there 142 142
in that UDP header because there's less 143 143
that needs to be contained. 144 144
And so, it allows us to have a faster, 145 145
more efficient protocol. 146 146
Again, you don't need to memorize these headers 147 147
for the exam. 148 148
But you should remember that TCP is bulkier 149 149
with its 20-byte header 150 150
than UDP is with its 8-byte header. 151 151
Because of this additional overhead in the TCP protocol, 152 152
UDP is considered much faster.