-
Notifications
You must be signed in to change notification settings - Fork 4
Networking Basics
Computer networks are used to connect machines and transmit data between them. When you open a webpage, your computer uses the network it is connected to and fetches the page's content from a remote server.
The most common of all networks is the Internet. It was originally designed for military communications and then used by universities across the world before becoming the global communication network that it is now.
As a developer, you will have to understand how computer network work to create application that communicate online. When developing such applications, understanding networking issues is very important to debug and improve your code. In the following, we cover the basics that you need to know about networking and internet.
On a basic level, Internet consists of a bunch of computers connected together. Each computer has a unique IP address. This address acts just like your regular postal address.
You can find the IP address of your computer using the command line. On Mac OSX and linux, the command ifconfig
returns a list of all the network interfaces used by your computer and their configured addresses. For instance:
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ether 44:2a:60:f2:b0:bc
inet 10.0.1.152 netmask 0xffffff00 broadcast 10.0.1.255
media: autoselect
status: active
Here, the interface en0
, which represents the wifi connection of my laptop, is assigned the address 10.0.1.152
. This a private IP address, as we explain later.
The address 10.0.1.152
is a IPv4 address. An IPv4
address is any value between 0.0.0.0
and 255.255.255.255
. That makes up for a total of roughly 4 billion possible addresses.
Although this seemed a lot in the 80s, when these addresses were defined, with the increase of online devices, laptop, tablets, smart phones, etc., we are quickly running out of IPv4
addresses. To solve this, a new version of IP addresses has been developed, called IPv6. A IPv6
address looks like this: FE80:0000:0000:0000:0202:B3FF:FE1E:8329
. Because it is longer, the number of possible IPv6
addresses is enormous, equal to 2128
. Although you may not see a lot of IPv6
addresses for now, they are expected to replace IPv4
addresses very soon.
Once you are connected to a network and have a IP address, you can send data to other computers using their own IP addresses. The internet does not require a specific transport mechanism. It is for instance possible to use homing pigeons to send your data!
However, most likely, you will be connected to the internet using either a ethernet cable or wirelessly through a local Wi-Fi connection.
Data send on the internet is split in small packets and transmitted one by one. There is no centralized routing on the internet. That means that each packet that you send can be transmitted though a different path in the network and, thus, the machine that they are sent to may receive them in a different order or even not receive some of the packet at all.
This may sound weird but you have to remember that internet was first designed as a military network. At the time, the most important concern was to be resilient to nuclear blasts. By using this design, the inventors of internet made sure that if a nuclear bomb would blast some of the network nodes, it would still be possible to use the remaining nodes to communicate!
You can see internet routing in action by using the traceroute
command line. For instance, here:
% traceroute google.com
traceroute to google.com (64.233.185.139), 64 hops max, 52 byte packets
1 192.168.43.1 (192.168.43.1) 10.178 ms
2 10.170.221.48 (10.170.221.48) 1034.910 ms
3 10.170.221.10 (10.170.221.10) 75.972 ms
4 10.177.31.185 (10.177.31.185) 68.779 ms
5 10.177.31.198 (10.177.31.198) 77.743 ms
6 74.125.52.99 (74.125.52.99) 81.158 ms
7 72.14.239.100 (72.14.239.100) 90.563 ms
8 66.249.94.6 (66.249.94.6) 84.247 ms
9 64.233.174.133 (64.233.174.133) 94.585 ms
10 *
11 64.233.185.139 (64.233.185.139) 377.557 ms
This shows one possible route from my laptop to google.com
using a total of 11 nodes. But if you run this command again, the route will potentially change to another one..