The application layer

      8 min read          

Hi! This is my second blog entry. As I mentioned in my previous blog entry, the first real blog post would be a summary about each chapter I liked in the “Computer Networking: a top down approach” book I am reading. This one is about chapter 2, or more specifically, about the application layer and how it works. It may not have all the data, but is a summary that I did and works for me. I hope you like it!

In the application development world there are two major architectural paradigms:

Client-server application:

The client-server application is where a host or end system (a client) requests a resource from another end system called the server. A client will request objects that are stored in the server, for example each image in an HTML document is an object. Each server will have a unique IP so that the client can reach it.

P2P:

P2P is an architectural paradigm that allows PCs to connect to each other and transfer files without the need of a middle device like a server. Each PC that downloads a file will also start working as a server.

Process communication:

It’s important to understand how processes communicate in the OS world. An end host will run a program that will communicate to another application in another host. In computer science, these are not the programs themselves but processes running inside each host. Processes within the same system use inter-process communication (IPC) which is controlled by the OS. If it’s a communication between two applications the processes will send and receive messages.

Socket API:

When a process sends a message, it goes from layer 7 (the application layer) down through a socket API to get to layer 4 (transport layer), so the socket API is an interface that divides both layers.

To be able to send a message to another host we’ll require an IP address, that is, a unique identifier to that specific host. We also require a port number, which is the way the other host identifies the application that the sending host requires. There are several port numbers that identifies different applications, for example HTTP uses port 80 and HTTPS uses port 443.

Throughput:

The throughput in networking is the rate at which the sending host can deliver bits to the receiving process. Bandwidth-sensitive applications are applications that require that the transport layer has a control of the minimum of throughput that the application can have in order for it to work. Elastic applications are applications that can work at any throughput level, such as email services.

Types of services offered in the internet:

Overview of HTTP:

HTTP stands for HyperText Transfer Protocol, which is used in the internet communication. HTTP is used in the client host and the end host, the client sends an HTTP request and the server will send an HTTP response.

Documents in the web are written in a markup language called HTML (HyperText Markup Language) and for our discussion, these are called objects. Within an HTML document we can have different objects, like images, so if we were to have an HTML document with 5 images we would have 6 different objects. Web browsers are the client (firefox or chrome), web servers (Apache or MS IIS) are at the server side.

HTTP is stateless, that is, it doesn’t keep information from the client. It works in the client-server architecture and uses TCP as its transport protocol to ensure the data delivery. The socket API will do the transfer between the application layer (HTTP) and the transport layer (TCP).

Types of connections:

HTTP format:

HTTP request

HTTP response

Cookies:

As HTTP is stateless and doesn’t keep any information of a person, we need cookies to identify a person exclusively. A cookie allow sites to keep track of users. If we contact a server, that server might give us a cookie as a response. This will make the HTTP client to send that cookie to the server each time it requests a file in the server. The server will get the cookie and will identify the person, so it can provide data based on the interests of that person.

Web caching:

A web cache (also called proxy server) is a device that sits in the middle of a connection and can respond to client requests quicker than the server where the site is hosted. Many browsers go to a web cache first by opening a TCP connection and then making an HTTP request, the web cache checks if it has the site that the client is asking for and if so, returns it. If it doesn’t have it, it will connect to the server with TCP and do the same HTTP request. When the server responds it forwards the response to the client and saves that website for later use. In the memory hierarchy, a cache is quicker than RAM (used by the server when looking for the website in its memory). So a web cache makes the internet more quicker. The web cache can act as a client and server at the same time, a server when maintaining a TCP connection with the client and a client when requesting the site to the server.

Web caches are mostly placed in the ISP to speed up internet lookups. CDNs nowadays geographically distribute web caches to allow this quicker lookup to take place. Google and MSFT have their own web cache.

Programming a UDP socket:

There are two things required for the packet:

  1. The IP address of the destination host
  2. The port of the service we want to reach (or were the server is listening for requests).

The following example uses socket programming in UDP, each line is commented with what it does. If we run the program (server and client) the client will run, ask for a lowercase sentence, send the message and wait for a response, print the response and then terminate. The server will always be running and listening on port 12000, as soon as it gets a request it will respond and print out some information.

UDP socket

Programming a TCP socket:

As TCP is connection oriented, we first need to establish a 3 way handshake. When this is done, the client side can start sending data. After all data has been processed the server will close the connection, meaning this is a non-persistent connection.

UDP socket


Code can be found in my github repository: Check it on Github

Source of the information: Computer Networking, a top down approach by James F. Kurose, Keith W. Ross.