Skip main navigation

Hurry, only 10 days left to get one year of Unlimited learning for £249.99 £174.99. New subscribers only. T&Cs apply

Find out more

It’s protocols the whole way down

it is time to focus on this aspect of networked programming and discover what protocols are and how they are used.

Over the course of the past two weeks, you have seen and heard about protocols and how they govern our communication via networks. In this step, it is time to focus on this aspect of networked programming and discover what protocols are and how they are used.

What is a protocol?

A protocol is a standard set of rules used to ensure the proper exchange or transfer of data between devices.

It provides both a framework and a set of features that applications can use. Observing the rules laid out in a protocol allows you to interact with devices across a network, as long as those devices know how to use the protocol, too.

A framework

Protocols provide a template for messages, describing what needs to be sent and in what order. They will also dictate the size of the messages you can send and receive. The template used to send data is called a frame, and you can see an example below:

A set of features

Protocols describe rules, but the template and other guidelines are designed to enable access to a set of features you can use in your applications. These features will depend on the layer the protocol operates in. Application layer protocols will have features that allow the end user to interact directly with services. Lower-level protocols, such as those on the internet and link layers, have features that enable transportation or handle IP addresses.

A packet and its many protocols

When you enter a URL such as https://www.raspberrypi.org you are telling your browser to find and retrieve the Raspberry Pi home page, using the HTTPS (Hypertext Transfer Protocol Secure) protocol to do so.

The HTTPS protocol provides a framework that will communicate a request for a webpage to a web server, but this protocol knows nothing about where the webpage is stored, or how to connect to it. Your browser will first send a request to a Domain Name Server (DNS) to get the IP address of the web server where the webpage is stored. It uses the DNS protocol to do so.

DNS

DNS provides a framework to ask the server questions. A question requires a domain name (raspberrypi.org) and a type of record that you want to access. In this case, your browser will request an A (short for address) record, which stores a host IP address for the domain name.

HTTPS request

Once your browser has the IP address (assuming the DNS request was successful), it will use the HTTPS protocol to form a request for the webpage from the server.

An example HTTPS request can be seen below:

GET / HTTP/1.1
Host: www.raspberrypi.org
Connection: keep-alive
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36
....

The HTTPS protocol has a few features you can use; the most frequently used is GET, which you can see in the request above. This request will get the home page that is linked to the host specified.

Other HTTPS request types are used to replace a webpage (PUT) or remove it from a server (DELETE), or to send the content of the current page (POST), which is used to submit data.

TCP

HTTPS requests are transported using TCP. This reliable communication ensures a server is listening before sending the request, thus guaranteeing a response.

TCP frames contain information about the ports to be used on both sides, and have designated bits for acknowledgements and other flags.

TCP is a transport layer protocol, and requires lower-level protocols to specify the destination IP address.

IP

Next, the IP protocol is used to set the destination of the HTTPS request.

The IP protocol encapsulates (wraps) the request and TCP frame in another template. A header is added, specifying the destination (returned from the DNS request) and source IP addresses for the data.

The final layer the packet has to navigate is the link layer: the physical hardware used to transport the data across the internet.

Link protocols are numerous and will change along the packet’s journey. Each connection the data travels across could cause a change in protocol.

The frames (templates) used on the link layer will all have the following information:

  • The destination and source hardware addresses, known as MAC addresses
  • The length of the data and frame
  • A checksum for the data
  • The timing and gap between packets that are to be sent

The list above shows you some of the information contained in link protocols. One of the most prevalent link protocols is WiFi.

What other information might be needed for a WiFi connection? Post your thoughts and reply to others in the comments section.

This article is from the free online

Networking with Python: Socket Programming for Communication

Created by
FutureLearn - Learning For Life

Reach your personal and professional goals

Unlock access to hundreds of expert online courses and degrees from top universities and educators to gain accredited qualifications and professional CV-building certificates.

Join over 18 million learners to launch, switch or build upon your career, all at your own pace, across a wide range of topic areas.

Start Learning now