Understanding various network protocols and HTTP requests made on Internet

·

6 min read

This blog contains a quick recap about various protocols used in Application Layer, the architecture and HTTP methods.

Application Layer

It is the layer where users interact with. Like browsers, whatsapp all these lie in the application layer.

So when we write our message, send our data it all happens in the application layer.

This layer lies on our devices.

The idea is when we send a particular data or request to any any server, it should be able to know how to deal with that request.

In Client- Server architecture remember the following thing :

The Client sends a 'Request'

The Server sends a 'Response'

The way the Client and Server communicates with each other are called 'Processes'.

To have a server a reliable IP address is required where Client can reach

We have a lot of servers in companies like Youtube, Civo. If we have many people trying to access a single server the server can go down. This happens when we try to access the exam results, book a concert ticket, shop on a black friday sale.

Usually you hear the term that 'website crashed', it means the server went down due to so many requests being made to it from the client side.

Peer to Peer Architecture or P2P Architecture

This is another way in which applications are connected to the client servers.

Various devices are connected with each other in this architecture, so there is no one server or large data center.

It can be scaled very rapidly and it is de-centralized as well.

Now where is the client and server in P2P? Actually every computer connected can become client as well as server as per requirement.

An example of this is Bit Torrent where any computer can download files as well as act as a server for another computer which wants to download some thing.

Protocols

Every application will have some protocol to connect with clients.

Some examples of TCP/IP protocols are listed below which you have heard earlier

Examples of TCP protocols

  1. HTTP - Hyper Text Transfer Protocol. It defines how data will be transfered on web pages.
  2. DHCP - Dynamic Host Control Protocol. It allocates the IP address to the different devices that are connected to a network.
  3. FTP - File Transfer Protocol. It decides how files can be transferred between client and server. This is being used less as files can now be transferred using HTTP.
  4. SMTP - Simple Mail Transfer Protocol. It defines how a simple mail is sent/transferred. TO receive an email we have different protocols
  5. POP3 & IMAC - THese protocols are used to receive emails.
  6. SSH - Secure Socket Shell. It is a cryptographic network protocol that let's access to computer services of any user over a unsecured network.
  7. VNC - Virtual Network Computer. It is used for graphical control to a remote computer. It transmits the keyboard and mouse input from one computer to another.

Telnet

It is a protocol that provides a command line interface for communication with a remote device or server. It connects between a local computer(which starts the connection) and a remote computer(which has to be connected). It is specifically designed for LANs. It is not a secure communication protocol! Over transfer of data important information can be easily collected using the packets being transferred. Telnet uses Port 23.

An alternative to TCP communication

UDP - User Datagram Protocol. It is a stateless connection so during the connection duration, data can be lost as it does not maintain any state.

UDP provides a different port number to differentiate between different user requests.

UDP is a process to process communication compared to TCP which is host to host communication. While transferring data for video streaming UDP is preferred over TCP.

Sockets

A network socket is an endpoint which is associated with a process and allows two-way communication with a remote application. Sockets are part of transport layer protocols, since we have two types of transport layer protocols, sockets are of stream and datagram types.

  1. Stream Socket - Before sending or receiving of data, a connection is established with the server and the data flows in streams of bytes in both directions. So this is a connection oriented bi-directional socket.

Once data is transferred client or server can terminate the communication.

  1. Datagram Socket - Before transfer of data, datagram sockets doesnot require any establishment of connection. The sender sends the packet which will be received by the receiver. If the receiver is not ready the packet will be lost. This is a faster way of data transfer but has high error probability.

Ports

"IP addresses tells us which devices we are working with, ports tell us will application we are working with." - Kunal

Consider we have many instances of Google Chrome running in the browser and we made a certain request from one of the tab. To understand how chrome will know which instance requires the data to be transferred once request is completed we have the concept of 'Ephemeral Ports'

Internally the device will assign itself with random port numbers if multiple instances are running. Once the process is done, the ports will be free.

These Ephemeral ports can exist on the client side but not on the server side.

We must know the port number on the server side. Servers thus need to have well defined ports so Clients can use it. One the request has been received by the server, internally they can assign random ports to process the request but when sending the response the port number has to be same as requested by the client. Hope that makes sense and doesn't confuse you.

HTTP

It is a client server protocol and it tells us how the data is being requested from the server and it also tells us how the server will send back the data to the client.

When a client makes a request it is called an 'HTTP request'. When a server sends back the response it is called an 'HTTP response'.

It is an application layer protocol and every application layer protocol requires some transport layer protocol.

HTTP uses TCP inside it because TCP(Transmission Control Protocol) makes sure the entire data is correctly transferred.

HTTP is a stateless protocol, so server will not store any information about client by default.

HTTP Methods

Methods are instructions given to server to tell them 'What to do!'

GET Method -

Give me some information

POST Method -

Send some information to the server

PUT Method -

Place the data at a specific location in server

DELETE Method -

Delete any data from server

Cookies

It is a unique string that is stored on the Client's device. You have often logged in into any website and later after closing and opening your browser again you did not needed to login again. This happens because the website stores some data in form of string to your own system and when you visit the website again it retrives it and makes your site visit experience convenient.