Learning Python Network Programming

(Sean Pound) #1

Network Programming and Python


The core protocols in the suite are designed to work together within a stack. That is,
each protocol occupies a layer within the stack, and the other protocols are situated
above and below that layer. So, it is layered just like a cake. Each layer provides
a specific service to the layers above it, while hiding the complexity of its own
operation from them, following the principle of encapsulation. Ideally, each layer
only interfaces with the layer below it in order to benefit from the entire range of the
problem solving powers of all the layers below.


Python provides modules for interfacing with different protocols. As the protocols
employ encapsulation, we typically only need to work with one module to leverage
the power of the underlying stack, thus avoiding the complexity of the lower layers.


The TCP/IP Suite defines four layers, although five layers are often used for clarity.
These are given in the following table:


Layer Name Example protocols
5 Application layer HTTP, SMTP, IMAP
4 Transport layer TCP, UDP
3 Network layer IP
2 Data-link layer Ethernet, PPP, FDDI
1 Physical layer -

Layers 1 and 2 correspond to the first layer of the TCP/IP suite. These two bottom
layers deal with the low level network infrastructure and services.


Layer 1 corresponds to the physical media of the network, such as a cable or a Wi-Fi
radio. Layer 2 provides the service of getting the data from one network device to
another, directly connected network device. This layer can employ all sorts of layer
2 protocols, such as Ethernet or PPP, as long as the Internet Protocol in layer 3 can
ask it to get the data to the next device in the network by using any type of available
physical medium.


We don't need to concern ourselves with the two lowest layers, since we will rarely
need to interface with them when using Python. Their operation is almost always
handled by the operating system and the network hardware.


Layer 3 is variously called the Network layer and the Internet layer. It exclusively
employs the Internet Protocol. As we have already seen, it has been tasked primarily
with internetwork addressing and routing. Again, we don't typically directly
interface with this layer in Python.


Layers 4 and 5 are more interesting for our purposes.

Free download pdf