Beginners guide to Networking-Part 02

Application Layer

Modern web applications are utilizing internet in a very astonishing way. We have instant messaging, Streaming services, Multiplayer games and so much more. To create such application we need to understand how OSI layers work with an application and what we as programmers need to know.

To write a program that should communicate through internet we should consider some stuff first. It should work with multiple end systems ( various desktops,laptops,servers and if its mobile it should run on various models of smartphones too). You have to be clear on which technology you use. Peer-2-Peer networking or Client-Host networking (aka Client-Server)

Client-Server model is the typical day to day websites we access. We type a url and then blah blah (we will get to this) we get the page with the text and all infront of us. What happens is as we sends a request the server that holds the webpages packets the webpages in packages and send them through the internet. Host have to be always available to serve the content the client asking. And the clients don’t communicate with each other. Host is capable of handling each and every clients individual needs, say you need to browse the same web address as your neighbour browses it at the same time. Both requests can be fulfilled by the server even you two request two different pages at the same time. If it can’t handle them most Hosts use scaling ( utilizing multiple resources, RAM,CPU etc) to create a one big virtual server that handles the requests of Million or Billion users all over the world (remember Google or pretty much everything these days).

Peer-2-Peer model (P2P from now on) rely less or don’t rely at all on the servers. The applications run on the users laptops or desktops and communicates with other users application directly. P2P is triumphs on the file sharing like Bittorrent because there is no central servers to control once the file is out there it literally cannot be stopped.

Here in the application layer…

  • Enables application to connect to the internet
  • Identifies communications partners
  • Determining the resource availability
  • Sync communications
  • Eg:
    • SMTP
    • HTTP
    • FTP

So how it works..

Let’s talk about Client-Host model. There have to be 2 processes (applications) one at each side. As a example requesting a webpage is the client side process is the browser. The server side process is serving the webpage to the said client. P2P model also has the client-host model embedded. The peer who requests the file is the client and the peer who sends or in the torrent word “seeds” the file is the host. All comes down how the application communicates with the other application. It’s done via a software interface called socket. If some process wants to commiucate through the internet it opens a socket in particular port number, and sends data. If some application in the internet has to share data with the process it first has to connect to the socket first.

Socket is the interface between application layer and the transport layer. In the application the developer has the full control of the everything. But not on transport layer. All he has on the transport layer is

  1. Choice of transport protocol
  2. mention extra abilities needed for the application such as maximum buffer

Transport Services provided by internet

Internet is made of 2 main services. TCP and UDP. These 2 has its own perks. We will talk about them separately.

TCP

TCP is connection-oriented service that originated from internet protocol (IP), commonly referred as TCP/IP. TCP provides reliable, ordered, error checked delivery of packets. Because of the reliability most of the services that requires data integrity and cannot lose a single packet uses this service. With features error checking and reliability comes with the price. It becomes relatively slow service than UDP.

When a typical TCP connection starts it usually does this handshake with either with its host to whom its gonna communicate. So both server and the client is ready to transfer the data and aware of the transmission. That makes path to data to travel between and checked for errors.

UDP

UDP is like a packet machine gun. If packets were bullets and the destination is the target post we all know what will happen. Not all packets will make it and also it will be fast. That’s UDP. In this case TCP is like sniper gun. You shoot good and wait and see the person get clearly shot. And move to the next person.

So there is no handshake protocol before sending data and doesn’t guarantee data reliability.

Application Layer Examples – HTTP

HTTP (Hypertext Transfer Protocol) is introduced in 1991 (not so long ago huh). Little bit of history about HTTP. It was initiated by Tim-Berners-Lee at CERN ,Short for European Organization for Nuclear Research ,as since the internet was invented and used by researchers and mostly to share researches I think that’s why a computer scientist in the particle physics laboratory comes up with the internet. HTTP was first defined in RFC2068 which was HTTP/1.1 . Now HTTP/2 and HTTP/3 is widely used.

When talking about HTTP there are few things we should know about. As mentioned in RFC2068 I will write it in a simple form.

  • Connection – A transport layer virtual circuit established between two programs to purpose of communication.
  • Message – The basic unit of HTTP communication, consisting of a structured sequence of octets.
Source: Mozilla Web Docs
  • Resource/Object – data object or a service that can be identified by a URI , like index.html or image.png.
  • Client – A program that establishes connections for purpose of sending requests
  • User Agent – The client which initiates a request, Often browsers.
  • Server – An application program that accepts connections in order to service requests by sending back responses.
  • Proxy – An intermediate program which acts as both server and client for the purpose of making request on behalf of other clients.
  • Gateway – A server which acts like intermediary for some other server.
  • Cache –
  • A program’s local store of response messages and the subsystem that controls its message storage, retrieval, and deletion. A cache stores cacheable responses in order to reduce the response time and network bandwidth consumption on future, equivalent requests.
Operation in HTTP

Basic operation comes from when the client or the user-agent requests files directly from the server and there is single connection of delivery.

We assume the devices below the application layer such as routers and switches will be automatically create the pathway in this scenario. Also in a complicated scenario there might be intermediate devices such as proxy,cache servers. HTTP is a stateless protocol. The server has no idea what the client requested before and doesn’t know what will be requested after. Also this single connection can be used only per object or it can be preserved to send multiple objects such as website + its images.

We call it persistent and non-persistent connections.

Before talking about connection types we should know that in order to create a connection we have to do a handshake with the server and the client. A TCP handshake also known as a three-way handshake gives the heads up to the server we are trying to transfer data. It’s called 3 way handshake because it involves 3 steps.

  1. SYN: The active open is performed by the client sending a SYN to the server. The client sets the segment’s sequence number to a random value A.
  2. SYN-ACK: In response, the server replies with a SYN-ACK. The acknowledgment number is set to one more than the received sequence number i.e. A+1, and the sequence number that the server chooses for the packet is another random number, B.
  3. ACK: Finally, the client sends an ACK back to the server. The sequence number is set to the received acknowledgement value i.e. A+1, and the acknowledgement number is set to one more than the received sequence number i.e. B+1.

So when every TCP connection have to do the 3 way connection to ensure lossless and reliable data transfer.

Back to the persistent and non-persistent connections. So when the client wants some object from the server it can choose whether it requires a persistent or non-persistent connection. If it requests file in non-persistent connection.

  1. TCP 3 way handshake takes place. Server opens TCP connection with the
  2. Client requests the object with a HTTP message.
  3. Server sends the object with a HTTP message.
  4. Server closes the TCP connection.

Imagine you have request a webpage in above scenario. First server sends the webpage you requests and closes the connection. And you browser parses the HTTP message it got from server and trys to display the HTML. But sees that it has couple of images linked to display. So to completely display the webpage it requests those images and any other objects (javascript etc) required to display the webpage correctly . But as we use non persistent connection each object request must follow the steps above from 1-4. Its time and memory consuming for the server.

In this case persistent connections comes into rescue. One TCP connection for all of the required files in a single 3 way handshake. Server keeps the connection open for further HTTP requests from the client for some time till the client or the server automatically kills the connection.

For further studies I recommend you to read…

And to the next protocol in Application layer…

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.