This series of blog will record the knowledge points and my understanding while reading the book,
Foundations of Python Network Programming.
Chapter 1 is an overview of network programming. It introduces some basic concepts in network field. As a beginner, I find it interesting to connecting some reality in life with these concepts. I feel like understanding something related to what happened around my daily life. I decide to write down these concepts piece by piece in this blog. I will try to write it down with comprehensive logic in the next following chapters.
An Example of Protocol Stack
- Google Geocoding API on the top (A way to query and fetch JSON data)
- URL name documents retrieved through HTTP
- HTTP supports document-oriented commands such as GET using raw TCP/IP sockets
- TCP/IP knows how to send and receive byte strings
Packet
The fundamental unit of sharing among network devices is packet. Packet is byte strings whose length might range from a few bytes to a few thousand bytes.
A packet has two properties at the physical level, the byte-string data and the address to which it is to be delivered. The address is a unique identifier that names one of the other network cards in the same Ethernet segment or wireless channel.
Explanation of network cards: it can send and receive such packets without making the computer’s operating system care about the details of how the network uses wires, voltage and signals to operate.
Internet Protocol
Internet Protocol is a scheme for imposing a uniform system of addresses on all of the Internet connected computers in the entire world and to make it possible for packets to travel from one end of Internet to the other.
IP Address
As mentioned in last session, IP imposes a uniform system of addresses on all Internet connected computers. So each computers will have an address. We might hear IPv4 and IPv6 from some of geek friends. To simply understand the the difference of IPv4 and IPv6, IPv4 is a 4 byte address. Each byte is separated by dot. IPv6 is in hexadecimal, which means IPv6 has much more addresses than IPv4. Recently, IPv4 almost has been run out.
It has meaning of the 4 bytes in IPv4 from left to right.
- First one or two: specify organization
- Next: subnet on which the target machine resides
- Last: narrows down the address to specific machine or service
There are also some special meaning address:
-
127.*.*.*: Special reserved range that is local to the machine on which an application is running. It is asking to speak to an address or program that is running on the same machine. Normally know as hostname called localhost
-
10.*.*.*, 172.16-31.*.*, 192.168.*.*: These IP ranges reserved for what are called private subnets meaning they are free to be assigned internally without choosing to make those hosts accessible from other places on the Internet.
Routing
While being asked to send dat ot a particular IP, OS decides how to transmit the data using one of the physical networks to which the machine connected. The decision is called Routing. Simply speaking, routing decides whether to keep the packet on local network or send it to the rest of Internet. But it is actually a complicated part in lower level.
Packet Fragmentation
Internet Protocol supports very large packets(up to 64 KB) in length. But actual network devices usually supports much smaller packet(1500 bytes). There is a DF flag(Don’t fragment) in packet transmission.
If there is no control over DF flag, we have two well-known solutions to packet fragmentation.
- UDP (User Datagrams Protocol)
- TCP (Transmission Control Protocol)
More details will be in the following chapters.