Showing posts with label CN. Show all posts
Showing posts with label CN. Show all posts

Tuesday 13 October 2015

SMTP

Simple Mail Transfer Protocol (SMTP)

After covering the Hyper Text Transfer protocol (HTTP) and File Transfer Protocol (FTP), now we are going to have a look at the another Application Layer protocol i.e. Simple Mail Transfer protocol (SMTP).

Introduction to Electronic Mail (E-Mail)


Electronic Mail or E-Mail has been among the most favorite Applications on the Internet for several years. It has become more and more powerful and secure over the years. It has been widely used throughout the Globe.

E-Mail is a asynchronous service i.e. you can send and read when it is convenient for you. You doesn't need to coordinate with other's schedule. Now a days, E-Mail has become so powerful that you can attach photos, videos, HTML files or any format file and send it.

An Internet Mail System has basically 3 components. 1. User-Agent. 2. Mail Server 3. Simple Mail Transfer protocol(SMTP). This Diagram will give you a overlook, how a mail system works.

Transfer of Mails between two Hosts, user agent, mail server, simple mail transfer protocol, smtp, outgoing message queue,http, ftp, email, steve, james


Now we will discuss all the above 3 components. To describe these, I will take a Sender , James, who is sending the E-Mail, to a receiver, Steve.

If we want to read, send reply or retrieve an E-Mail, we do all this with the help of a user-agent. For Example, Microsoft-Outlook is a user-agent for Email. After James is done with writing the mail,, his user-agent sends the message to his mail server. In the mail server, the mail is stored in the mail server's outgoing queue. When Steve wants to read that mail, his user-agent retrieves the mail from his mailbox in his mail server.

Every recipient has a mailbox located in the mail servers. A mail starts from a user-agent travels to the sender's mail server, after that message reaches the receiver mail server, where it is stored in the receiver mailbox.  Now Steve comes to read the mail in his mailbox. Thus, the mail server containing his mailbox will authenticate the Steve with his username and password.

Mail Servers are core item in a Email structure. James mail server must take care of the failure in Steve mail server. If the sender mail server is unable to send the mail, then it holds the mail in its queue and will attempt to deliver the message later. The reattempts to send a message are mostly done every 30 or 40 min.  But if the message is not sent for few days, then the mail server removes it from the mailbox and informs the sender with an e-mail.
As HTTP and FTP, SMTP also has a client and a server side. The mail sender behaves as a client whereas the mail receiver behaves as a server. When a mail server sends a mail to other mail server, it acts as a SMTP client. When a mail server receives mail from other mail server, it act as a SMTP server.

Introduction to Simple Mail transfer Protocol (SMTP)


SMTP is used to transfer mail from sender's mail server to the recipient's mail server. Along with the number of advantages of SMTP, there is also a disadvantage or you can say , an old-fashioned characteristics of SMTP. The message sent in a SMTP mail, should necessarily be in 7-bit ASCII format. This is the restriction that SMTP apply on the mails. In today's world of Multimedia where a large number of Photos and videos are being sent over mail, 7-bit ASCII is a pain. Thus, before sending a binary coded multimedia data over SMTP, it has to be converted into 7-bit ASCII and on the receiver side, it has to be decoded back to binary after its Transport.

James sending mail to Steve.  Lets have a look:


1. Now James opens his user-agent to send a e-mail. He provides Steve e-mail address, writes or composes a message and tells the user agent to send the message (by clicking on the send button).

2. James user-agent send this mail to James' mail server, where the message gets placed into the message queue.

3. The SMTP client side, that is running on the James mail server, see the message in the queue. Then it opens a TCP connection with the SMTP server, that is running on Steve mail server.

4. After the handshaking process, the SMTP client sends the message into the TCP connection.

5. The SMTP server side receives this message. Steve's mail server then places this mail in his mailbox.

6. Then Steve according to his convenience opens his user-agent, authenticates himself to the mail server and reads the mail.

Let me describe these 6 steps with the help of a figure:

Sending of Mail from james to steve,Transfer of Mails between two Hosts, user agent, mail server, simple mail transfer protocol, smtp, outgoing message queue,http, ftp, email, steve, james
A very enchanting feature of SMTP is that SMTP doesn't store the mail in any intermediate mail server. For example: If a James mail server is located in India and Steve's server is located in USA, then the TCP connection will be directly between India and USA servers. No intermediate server will be there. You can say that, if Steve server is down, the message will remain in James mail server and waits for the next attempt.

A general message that is being sent through SMTP is as follows:
Suppose server(S) name is India.com and client(C) name is USA.com.

S : 220 India.com
C : HELO USA.com
S : 250 Hello USA.com, Nice to meet you.
C : MAIL FROM:<James@USA.com>
S : 250 James@USA.com.... Sender OK.
C : RCPT TO:<Steve@India.com>
S : 250 Steve@India.com... Recipient OK.
C : DATA
S : 354 Enter Mail, end with "." on a line by itself.
C : Do you have a Grammar Book?
C : What about Atlas?
C : .
S : 250 Message accepted for delivery.
C : QUIT
S: 221 India.com closing connection.
The SMTP uses a persistent connection. Therefore simultaneous message are being over the same connection. Like, the Client send the "Do you have a Grammar Book?" and the "What about Atlas? , together on the same TCP connection.
You can try the above script in the "Command prompt" of your system. 
Before starting, give a command,   <telnet servername 25>
Here sever name is the name of your local mail server. And 25 is the default port number for SMTP. With this command , you are establishing a connection between your local host and the mail server. If the connection is established, then you must get a 220 reply from the server. And after start with the above commands and send a mail.

SMTP and HTTP:

HTTP and SMTP both protocols are for transfer of files from one host to other. They both use the persistent connections and send number of files over the same TCP connection. HTTP transfer files from server to client and SMTP transfers mails from one mail server to other mail server.
There are some differences between HTTP and SMTP. These are:

1. On one hand where HTTP is a pull protocol. On the other hand, SMTP is a push protocol.
  • HTTP is used to pull or extract the information from the server to the client. SMTP is used to push or to put the information from the sender's mail server to the receiver's mail server.
2. HTTP retrieves the data as it is in its original form only. But SMTP requires every message to be in 7-bit ASCII format. If the message is not in 7-bit ASCII or it is binary, then it has to be converted into 7-bit ASCII before sending over SMTP.
******  If you want to know more about Email services, I will ask you to read RFC 5321.******
 I am done with the Simple mail Transfer protocol (SMTP).  In the coming post, I will tell you about one more Application Layer Protocol i.e. Domain Name System (DNS).

DNS

DOMAIN NAME SYSTEM (DNS)

After Covering HTTP, FTP and SMTP, now we will discuss about another Application layer protocol, DNS. DNS stands for Domain Name System.

Before starting I would like to ask you , how do you identify human beings. I am sure , your answer will be , by their names. But I want to tell you that , there are also other ways of identifying a human being. Such as from their Driving License, from their passport Number etc. For example, If you work in a industry, where 1000's of employees work. And there is a database, that store the information of every employee according to the Serial Number id of that employee. So for the database, your serial id is an appropriate option to remember you. But your friend will not use that serial id, he will call you by your name only. Therefore, we humans can be identified in different ways, those different ways can be used for different preferences where appropriate.

Similarly the Internet hosts are identified in many ways. One way is to identify them by their host names. For Example : Hostname can be www.google.com, yahoo.in , network.edu etc. But these host-names are appreciated by humans only because hostnames are easily readable by them. Hostnames provide some information about the host. Say, if a hostname is www.school.edu.fr. Thus the .fr at the last refers that the host might be located in France. Except that it tells nothing.

But hostnames can be of variable lengths. What about the routers. it will be difficult for them to process these variable length hostnames. Therefore, for these reasons, hosts are also identified by IP-addresses.

IP address are the fixed length numbers. These are of 32 bits or 4 bytes such as 198.168.32.45. Each of the 1 byte or 8 bits separated by a decimal, can contain number for 0 to 255. These 4 bytes follow a hierarchical structure. For example, if you read a postal address on a letter, you will keep getting a more idea as you go down reading it, that where the address is located. In the same way, as we keep scanning the IP address from left to right, we will keep getting more and more information about the host, where it is located.


Importance of Domain Name System (DNS) :

Above we have discussed two ways of identifying a host. Either by their hostname or IP address. Human prefers hostname while the routers prefer IP addresses. Therefore to fulfill these preferences, it is a need that there should be directory that transforms the hostnames into routers understandable IP addresses. This work is done by Domain name System. It transforms the hostnames into their respective IP addresses.
Therefore we can say that, DNS is a database or a distributed database that is implemented in a hierarchy of DNS servers.
Also DNS is an application layer-protocol that apply queries to that database. DNS is used or implemented by the other Application Layer Protocols like HTTP to translate the human provided hostnames to IP addresses.
Lets discuss this with an example. Say, you type a URL in your Browser ( a HTTP client), www.com2networks.com/ images.png. Thus, for the client host to send the HTTP request to the Web Server www.com2networks.com, the user host must obtain the IP address of www.com2networks.com. These are the steps that took place when you type the URL in the Browser and press Enter.
1. The user or the client machine executes the client side of the DNS.
2. The Browser extracts the hostname from the URL i.e. www.com2networks.com, and delivers it to the client DNS.
3.The DNS client sends a message containing the hostname to a DNS server.
4. The DNS server replies back with the IP address of the requested hostname to the DNS client.
5. Now the browser receives the IP address from client DNS, it can setup a TCP connection to the HTTP server at that IP address. ( Connection with HTTP process at port 80).
  • You must have noticed that except a HTTP request-response, now there is a added DNS request-response also, resulting in the additional delay. 
The DNS servers are often UNIX machines running on the Berkeley Internet Name Domain (BIND) Software. And the DNS protocol runs over UDP at port 53.
There is certain other services also that are provided by the DNS. I am telling you one of those which is the most important of all..

HOST ALIASING: 


A hostname can be very complicated to remember . For example: east-country.education.girls.school.com . Thus, 1 or more alias name can be made for it, such as school.com or www.school.com. Hence , in this scenario, the east-country.education.girls.school.com is said to be the canonical hostname. DNS can obtain the canonical hostname as well as the IP address of a host.

Other service of DNS is Load Distribution.

Working of DNS and Issues Related With It :


Now you know how DNS works. When the browser wants to transforms a hostname into IP address, it invokes the DNS client . The DNS in the host sends a query into the network. After some Delay, the DNS in the user host gets a reply message within UDP datagram at port 53 that provides the correct IP address for the requested hostname. You can see that , DNS provides a simple translation service behind the scene i.e. you can also say that it acts as a black box. But in reality, this is very complicated phenomenon, that consists of  thousands of DNS servers that are distributed among the globe. And also an Application Layer Protocol that regulates how the DNS servers and the requesting hosts communicate.
Now its possible that here is a single DNS server that contains all the IP addresses and the related mappings. The hosts just query the single DNS and the DNS responds directly to the requesting host. But in Today's Internet, where millions of hosts are requesting at a time. Thus, for a single DNS to process all queries is impossible. There are certain problems associated with this centralized DNS design. These are:
i) DNS failure: If at some point of time, this single DNS server crashes or stops, then the whole Internet is dead.
ii) Far Away DNS:  For example, if the single DNS is put in Australia, then all the requests from USA have to travel the whole globe to process their requests, resulting in large delays.
iii) Traffic : There are millions of users around the globe, thus making it almost impossible for the single DNS to process all the requests.
iv) Maintenance: Every day , large number of new hosts are getting added to the internet. Thus, the single DNS have to updated with these records. Hence making it very difficult to maintain.
You can now illustrate that a centralized DNS is not possible in today's Internet. Thus, distributed DNS are implemented all over the globe to provide a better and a fast service. We will discuss the Distributed DNS in the next Post. Now coming to DNS Records and Message Format.

DNS Records:

The DNS servers that together implements the DNS distributed database , store Resource Records(RR's). including RR's that provide transformation from hostname to IP address. Each DNS reply message contains one or more resource records.
 A Resource Record(RR) has four fields:
(Name, Value, Type, TTL)

TTL= Time to Live

TTL determines, when the record should be removed from the cache.
The DNS servers have record in 4 types that have different fields for RR's. These records are as follows:


a) If Type=A, the "Name" is a "hostname" and "Value is the IP address "of the hostname. For example:(shop.kung.com, 127.134.87.197,A). This a Type A example.
b) If Type=NS, then "Name" is "Domain(as kung.com)" and the "Value" is the "hostname of an authoritative server" that will know , how to obtain the IP address of the host. For Example: (kung.com, dns.kung.com, NS). This is a NS Type Records.
c) If Type=CNAME, then "Value" is a canonical hostname for the alias hostname and "Name" will provide the "Domain name" for the hostname. For Example:(kung.com, shop.cloth.metre.kung.com, CNAME). This is CNAME Type Record.
d) If Type=MX, the "Value" is the "canonical Name" of a mail server that has a Alias Name. For Example:(kung.com, mail.shop.kung.com, MX). 
  • MX records enables the hostnames of mail servers to have easy alias names. 
  • MX also enable an organisation to have same alias name for its mail server and one of its other server. 
  • To get the canonical name for the mail server, a DNS client would query for a MX record and to obtain the canonical name of the other server, the DNS client would query the CNAME record.



DNS Message Format :

There are two types of DNS messages. DNS query and DNS reply. The format of both these messages is same. Lets have a look at the message format of DNS.
Domain Name System Message Format, Dns message format, root server, top level domain name server, authoritative server, computer networks, personal area network, local area network
1. The first 12 bytes or 96 bits, are called as the header section, which has 6 fields. The Identifier filed is of 16 bits, that is a number which identifies the query. A Flag contains 1 bit number, either 0 or 1. If the Message is a query, the flag is set as 0, and if the message is a reply, flag is set to 1.

2.The Next 4 fields i.e. No. of Questions, No. of Answers, No. of Authority RR's and No. of additional Information RR's. contains information about the Number of Occurrences of the Below Given Fields.

3. The Question Section Contains the information about the query. This Section includes two things. 1. A Name field that contains the name of the query. 2. A Type Field that contains the type of question being queried. For Example: A host Address associated with a Name of Type A.


4. In the Reply from the DNS server, the Answer Section contains the Resource Records for the name, that was queried.

5. The information about the Authoritative Servers is contained in the Authority Section.


This was all I had in Introduction, Basics and Message Formats of Domain Name System. In the next Post, Continuing with DNS, I will discuss about Distributed Structure of DNS and DNS caching.

FTP

FILE TRANSFER PROTOCOL (FTP)

After covering the Hyper Text Transfer protocol, now we are going to have a look at the another Application Layer protocol i.e. File Transfer Protocol.

In a File Transfer, the user or the local host wants to transfer files from remote file system to the local file system and vice versa. In order to access the remote account, the user has to authenticate himself by providing a username and a password. After filling this authentication information , the user can transfer files to or from the remote host.

The user or the host interacts with the FTP server with a FTP client or user-agent. The user provides the hostname of the remote server, that causes the FTP client process in the local host to establish a TCP connection with the FTP server process in the remote host.

Note: ******** For HTTP user, Browser acts as a client. Therefore for FTP , you need to install a FTP client or a user-agent that can interact with the server. *********


The user then provides the username and the password that are sent over the TCP connection as FTP commands. After the server authorizes the user, the user can copy files from local file system to the remote file system and vice versa.


COMPARISON BETWEEN HTTP & FTP


Hyper Text Transfer protocol and File Transfer protocol both are for the transfer of files from one host to other. There are many common characteristics among them. For example, FTP and HTTP both run over TCP.

But there are many differences between them. So we will discuss the differences.

i) FORMAT : HTTP only uses Binary Format whereas FTP can data both in ASCII and Binary Format.


ii) META-DATA :  HTTP headers contains metadata such as last modified date, server name, version and many more but these all are absent in FTP.
iii) CONNECTIONS : While HTTP have a persistent connection and can transfer as many files on a single TCP connection. In FTP a different connection has to be made for every individual file transfer.

iv) SPEED : There are various parameters on which the speed of HTTP or FTP is justified.

                              **** Why FTP is faster ?
                                              As there is no meta-data in FTP, so FTP is faster.

                                **** Why HTTP is faster?
                                              There is a persistent connection in HTTP, so it is faster.


v) USER-AGENTS or CLIENTS: In HTTP, browser is the client, In FTP , your command prompt can act as a client.
vi) Now the most important difference between a HTTP and FTP is that HTTP uses a single TCP connection to request and transfer files. On the other hand, FTP uses two parallel connections to transfer a file. These connection are known as Control Connection and Data Connection.


  • The information such as username, passwords, commands to 'put' or 'get' files are sent by Control Connection.
  • The actual files are sent over Data Connection.


 Because of this property of FTP , it is known as out-of-band protocol. As it uses a separate control connection to send the control information. You must remember that HTTP uses the same TCP connection to send request and receive response. Therefore HTTP is said to be as In-Band Protocol.


FTP data Connection, FTP control connection, out of band protocol, meta data, remote server, local host, remote file system, local file system


Working BETWEEN FTP CLIENT AND FTP SERVER:

The FTP client initiates a control TCP connection with the server on port number 21 , before a user starts an FTP session with the remote host. The user sends its username and password over this control connection. When the server receives a request ( in the form of FTP command) for a file transfer over the control connection, the remote host initiates a TCP data connection to the client. Only one file is sent over a data connection and then the data connection is closed. If, during the same session, the client wants to transfer one more file, then FTP opens another data connection. This implies that, the control connection remains open for the whole session in FTP, but always a new data connection is generated for transfer of every new file. That means, data connection is non-persistent.
Also, FTP maintains a state information of the client. Therefore, if the client transfers the same file during the same session, the remote host will warn it and will not allow it. Thus, FTP is said to be as the STATEFUL Protocol. On the other hand , HTTP is a Stateless Protocol - doesn't maintain any state of the client.




FTP data Connection, FTP control connection, out of band protocol, meta data, remote server, local host, remote file system, local file system, speed, tcp connection, http


COMMANDS IN FTP

As request and response commands in HTTP were there. Similarly there are FTP commands.


User Commands:


These commands are request from client to server. These are in 7-bit ASCII format. Thus, they are easily read by a human being. Some of the FTP commands are:

i) USER username : It is used to send the username to the server.

ii) PASS password : It is used to send the password to the server.

iii) RETR filename : It is used to retrieve or to get the file from the server. This command causes the remote host to initiate a data connection.

iv) STOR filename : It is used to store a file on to the server.

v) LIST : It is used to ask the server to send back all the files in the current directory. The list of files is sent over a new data connection, but not over the control connection.


Server or Remote Host Commands :

These are the responses from the server to the client request. These are also 7-bit ASCII format.

i) 331 Username OK, password required

ii) 125 : Data Connection already open. Start transfer of files.

iii) 425 : Error opening data connection

iv) 452 : File cannot be write or Error Writing file


******* If you are really interested to know more about FTP, I would ask you to read RFC 959 in order to get a deep knowledge of the FTP commands and replies.

HTTP

Hyper Text Transfer Protocol (HTTP)

Now after Discussing all the basic concepts of the Application Layer, we should now look at its different protocols. There are various protocols in the Application Layer such as HTTP, FTP, DNS, SMTP. Each protocol is used for the purpose of using different Application.  First, we should start with the HTTP protocol.


Internet and HTTP:

Before the early 1990s, the Internet was not common to every human being , as it is now. The Internet was only used by researchers and some universities. These researchers and university students use to Internet to log in to remote hosts , to transfer files from client host to remote hosts and vice-versa. Internet was used by them to receive and send mails and news. But as in early 1990s , a new application arrived in the market that was known as World Wide Web (www). The Web changed the course of the computer networks. It changed the thinking of the people , that how the people interact and communicate , inside and outside their work environment. The most promising feature of the WEB , that attracted lot of users towards is that Web works on Demand. Any user can get anything at any-time of the day he wants. There were certain other very amazing feature that people love and admire. Anyone can become the member of the Web, Anyone can publish his/her thoughts and much more. And finally after 2000,  the Web serves as a base or a platform for many superb applications such as Gmail, Facebook and YouTube.

Now before directly coming to the explanation of HTTP. I want to make you familiar with some very basic terms.

  • A Web Page
  • A HTML file
  • A Web Browser or a Client
  • A Web Server
i) A Web page consists of objects. These objects can be images or an HTML file etc. An HTML file is the reference to the other objects in the web page. It refers the object with the object URL. The URL has two things in it. 1. The host name and 2. The object address or the path name. For example:

Suppose this is the site name http://imraan-prrec.blogspot.com/computer-networks/LAN.png

Here, imraan-prrec.blogspot.com is the host address and the computer-networks/LAN.png is the path of the image where the image is present.


ii) Web browser or the client is the host that sends a HTTP request message.

iii) Web Server is the host that services that request and sends HTTP response to it.


  • Default Port Number of HTTP is 80.

Let me try to clear you by drawing a figure. Look at the figure to understand the HTTP request response mechanism..

HTTP request response messages, hyper text transfer protocol, computer networks, client server architecture, browser, suggestions, comments
*******Before moving on, I should clarify you with 2 things and then will get further:
(a) Web uses a Client-Server Architecture where there is a server that is always on with a fixed or static IP address and responds to thousands of request from different clients or browser.
(b) And I am using Browser and Client Interchangeably. When you requests a Web Page from your Laptop, you always use your Browser. So don't get confuse by client or browser. They are same.  *******
HTTP defines everything for a Browser (Client) and a Server. How a Client should send a request message for a Web Page to the server,  what should be the format of that message and how the server responds to that request by sending the Web Pages to the Client and what is the format of the response message. All these aspects are defined by the HTTP protocol.
The underlying protocol that HTTP uses is TCP(Transmission Control Protocol). The HTTP client or the browser initiates a TCP connection with the sever. After the connection is established, the browser and the sever access TCP through their socket interfaces. 
As I have told you in the previous posts that Socket is the door between the Client Process and the TCP on the Client Side and on the sever side it is the door between the server process and the TCP. 
The Client sends its HTTP request message into its socket and receives the response message from the socket interface. In the same way, the server receives the HTTP request from the socket and sends HTTP response into the socket interface. Once the Client sends the message into its socket, the control over the message is out of his hands and TCP take its control now. 
TCP possesses  a property that it guarantees a Reliable Delivery of Data. That means if a message is hand over to TCP , it will surely reach to its destination.(No guarantee of , how much time taken). So the HTTP request message sent by the client must reach the server and the server HTTP response message must reach the client. 
  • We will discuss about TCP in Detail in the later posts of Transport Layer. Till now, you should remember that it provides a Reliable Data Delivery Service.

Here you see a big advantage of Layered Architecture. That HTTP should not worry about the transfer of the message. HTTP need not worry about the lost data. Its the job of Transport and the lower lying layers.
One more thing that I should bring to you is that server doesn't make any record of the client. It just sends the requested file without making any record of the client. For example, if you request the same file thrice in spam of 2 seconds, the server will resend you the same file 3 times. It will not alert you that you have just requested that file because server has forgotten everything what it did before. Because of this, HTTP is said to be as STATELESS PROTOCOL. As it is not storing any state of the client. 

This is all with the basics of HTTP. In the further posts, I am going to tell you about the Types of HTTP connections and message format of HTTP protocol.

HTTP Format

HTTP Types and Its Message Format

Moving on with our discussion on Hyper Text Transfer Protocol (HTTP). If you have forget something about HTTP, then you can go to this link and revise it, and then start with this post. HTTP Revise..

In this post, I am going to tell you about the types of HTTP connections and HTTP message format.


First we will start with the HTTP connection types. There are basically two types of HTTP connections: Persistent and Non-Persistent. Lets have a look at each one of them.

When you or any host communicate with the server, there is a long series of request-response messages, that is being exchanged between you and the server. Therefore, depending on the type of application, the Application developer has to make a decision, that should all the request-response messages should be sent over a single TCP connection or they should be sent under individual TCP connection for every pair of request-response message.

If all the request-response message pair are sent over different TCP connection, it is known as Non-Persistent Connections and if there is only one TCP connection for a series of messages, it is known as Persistent Connection.

Hyper Text Transfer Protocol (HTTP) with   non-persistent connection :

Let me start by giving you an example that will make you understand about HTTP non-persistent connection. The transfer of a Web Page from server to client under non-persistent connection is as follows:
Let us suppose that a web page consists of a base HTML file and 20 PNG images, all these 21 files reside on the same server. Say, the address or the URL of the base HTML file is http://www.com2networks.blogspot.com/department/images.html.
Now the process starts.
1. The HTTP client process initiates a TCP connection to the server www.com2networks.blogspot.com on port number 80, the default port number for HTTP. There will be a socket at the client and a socket at the server associated with the TCP connection
2. The HTTP client sends an HTTP request message to the server via its socket. The request message includes the path name /department/images.html.
3. The HTTP server process receives the request message via its socket, retrieves the object /department/images.html from its storage, encapsulates or embed the object in an HTTP response message, and sends the response message to the client via its socket.
4. The HTTP server process tells TCP to close the TCP connection.
5. The HTTP client receives the response message. The TCP connection terminates. The message indicates that the encapsulated object is an HTML file. The client extracts the file from the response message, examines the HTML file and finds references to the 20 PNG objects.
6. Now to get those 20 PNG images, the first four steps are again repeated.
The steps above explains you the use of non-persistent connections, where each TCP connection is closed after the server sends the object—the connection does not persist or remains for other objects. Each TCP connection transports only one request message and one response message. Therefore in this case, when a user requests the Web page, 21 TCP connections must be generated.
Lets now see into the depth of non-persistent connection and calculate the time taken from requesting a web page and till the entire file is received.
Here I will describe you the time taken by a small packet to travel from client to server and back to client. This is known as Round-Trip Time (RTT). The RTT includes the packet propagation delay, queuing delay at the router and switches and the the processing delay.
What happens when you click on a link or a hyperlink , the client or your browser initiates a TCP connection with the server. This connection involves 3 steps that are often called as "3-way handshake". This handshake includes, (a) The client sends a TCP segment to the server, (b) The server acknowledges and responds with a  TCP segment, and finally (c) The client acknowledges back to the server.
The 1st two parts (a) and (b) takes 1 RTT. After completing the 1st two steps , the client sends a request message along with the 3rd part of handshake i.e. acknowledgement to server. After receiving the request message and acknowledgement , the server respond by sending the HTML file into the TCP connection. This HTTP request-response takes 1 RTT. So approximately, we can say that, Total response time taken is 2 RTT's plus the transmission time taken by the server. Now as usual, I will clear  it by drawing a figure for you.
round trip time, rtt, propagation delay, queuing delay, file transmission, transmission delay,
         Figure: TIME TAKEN IN TRANSMISSION OF A HTML FILE

Hyper Text Transfer Protocol (HTTP) with persistent connection :

As we can clearly see that , non-persistent connections have certain disadvantages. For every requesting object, you have to set-up a new TCP connection that is a huge overhead for a server that is serving millions of requests. And also, it will take 2 RTT for every requested object.
To overcome theses issues, HTTP is used with persistent connections. In persistent connection, the server doesn't close the connection after sending a response. More than one request and response can be sent between the same client and the same server over the same TCP connection. The example we have taken above of an HTML file and 20 PNG images. So these 21 objects can be sent over a single persistent connection.The request for different objects are made simultaneously without waiting for the replies to the pending requests. This phenomenon is often called as pipelining.  When the server receives back-to-back requests, it sends the objects back-to-back. The server closes the connection , when the connection remains useless or idle for a particular time period.
  • The default mode of HTTP uses persistent connections. However an application developer can modify it to non-persistent according to his need.
Now lets move on and have a look at the types of HTTP message formats. As you already know, there are two types of HTTP message. One is Request message and the other is the Response message.

HTTP REQUEST MESSAGE

GET    /department/images.html    HTTP/1.1
Host : www.com2networks.blogspot.com
Connection : close
User-agent : Chrome/7.0
Language : Fr


Have a look at this message and try to understand it. You can see that the message is written in ASCII text, so that an ordinary human being can read it. As this request message contains 5 lines. Similarly a request message can have more lines and as few as 1 line also.

In this example, the 1st line of the message is said to be the request line and the further are called the header lines.

Request line: It has 3 fields: (a) Method field, (b) URL field and (c) HTTP version field.
There are various methods that can be there in a method field such as GET, POST, PUT, HEAD, DELETE.

GET:    The GET method is used for general web page request.
POST:  The POST method is used to ad parameters to the server.

The URL field contains the address of the requested object. As here, it is /department/images.html.

Version field: Version of the HTTP that browser implements, here it is version HTTP/1.1.


Now the header fields.

1st header field contains the host i.e. www.com2networks.blogspot.com, tells the name of the host on which the objects reside.
2nd header field Connection:close , browser tells the server that it doesn't want to bother with persistent connection. It wants server to close the connection after sending the requested object.

3rd header field User-agent : Chrome/7.0, a chrome browser. This field is useful in the cases where the server has different copies of the files for different version of user agent.

4th header field Language: Fr. It tells the server in which language , the desired copy of the requested file is wanted. Here it is French. If the server has the requested copy, it will send that, but if it doesn't , then it will response with the default version.


Now let me give you a  general format of HTTP request message.
HTTP request message, header filed, request line, department, connection

HTTP RESPONSE MESSAGE

HTTP/1.1    200     OK

Connection: close

Date: Fri, 06 Sept 2013 11:45:07 (GMT +05:30)

Server: Apache/2.2.3 

Last-Modified: Sun, 01 Sept 2013 15:11:03 (GMT+05:30)

Content-Length: 4951

Content-Type: text/html

(data data data data data ...)

A response message could have more number of entries also. But we will discuss this basic message with 8 entries.

Have a look at this message and try to understand this. It basically has 3 sections. 1. An initial status line 2. Header lines 3. Entity body.

1. Status Line: It has 3 fields. (a) The protocol version. (b) A status code. (c) Status message

In the given message, the server is using HTTP/1.1 version and the code is 200 , that means everything is OK and executed properly (The server has found the object and sending it).

  • Some common Status Code that you will generally get as response from the server, while   requesting for a Web page are:


                         (i)  200 OK : It means , The Request succeed and the requested information has been sent.

                        (ii) 301 Moved permanently : It indicate that the requested URL has been permanently                  moved to a new address. This new URL will be indicated in the Location, header of the response message.

                        (iii) 400 Bad Request : When server doesn't understand the request, it shows this code.

                         (iv) 404 Not Found : The requested information doesn't exist on this server.


2. Now the header fields.

1st header field Connection : close, The server wants to inform the client that it is going to close the connection after sending the object.

2nd header field DATE : It indicated the time and the date when the HTTP response was sent by the server.

3rd header field Server : The name of the server used to generate the response message.

4th header field Last-Modified : Its the time and the date when the object was last created or modified.

5th header field Content-Length : It tells about the number of bytes in the response message that are being sent.

6th header field Content Type : It tells that the object in the entity body is a HTML text.


3. Entity body that is being denoted by data data data data....... is the meat of the message . It contains the requested object.


Let me give you a general format of HTTP response message.



http response message, header fields, connection, status line, header lines, entity body
 I am done with the HTTP protocol. In the coming posts , we will discuss about the other Application Layer Protocols such as FTP, SMTP, DNS

Network

COMPUTER NETWORKING

A network is a collection or a group of people interacting and sharing information with each other, So in the same way , a Computer network is a group of computer that interacts and share information with each other , connected by some communication links such as wires, cable or wirelessly. It is all about transmitting message from sender to receiver and vice-versa. A computer network can be wired and wireless.
There are various mediums to make a wired network. These are:
Mediums to form a wireless network are:
There are various kinds of Networks. These are:
i) Personal Area Network (PAN):

A Personal Area Network (PAN) is a computer network that is used to transfer messages between a computer and other technological devices that belongs to one person only.  Example of such devices are a laptop or desktop, fax machine, Personal Digital Assistance (PDA) or Palmtop computer, scanner , printer etc. The range of a PAN is around 10 metres. 
ii) Local Area Network (LAN):
A  Local Area Network (LAN) is a computer network that is set-up within a home, college, institution, college and there nearby buildings. The connected computers are called nodes of this computer network. The wired LAN can be formed using an Ethernet cable. The range of a LAN is about 100-150 metres.
iii) Metropolitan Area Network (MAN):
A Metropolitan Area Network (MAN) is a computer network that is set-up for a whole city or a very large area. MAN can cover a region of almost 30-40 kilometres. 
iv) Wide Area Network(WAN):
A Wide Area Network(WAN) is a computer network that is set-up along a big area such as a WAN covering two or more cities, a country, a continent. The best example of WAN is Internet.
Now after defining the network analogies, we should move on to the Internet and should look into some aspects of Internet.

When we talk about internet , we all have some very basic questions about internet. So here are the answers to your questions..

Ques 1. What is an Internet ?

Internet is a collection of computers i.e. it is a network of networks in which million of computer are connected and interacting with each other. People are connected to the Internet from all over the world through different devices such as desktops, laptops, smartphones, tablets etc. These all devices in networking are called as hosts or end users or nodes. According to a survey conducted in 2011, more than 2 billion hosts were connected to Internet.
Ques 2. How do different end users communicate with each other over computer networks?
Now directly before answering your question, I want to ask something from you. Suppose when you want to ask time from a stranger. How do you do it. You first say "Hi" (Greet message) to initiate the communication, then he will reply you with "Hi"( a message that you will take as an indication, that the receiver is willing to communicate and you can proceed to ask time). Or the other replies could be "Don't bother me" or "I don't understand your language", indicates the unwillingness to communicate. So you would not ask time.
These were the human protocols, that before initiating you should say a "Hi" or "Hello"(or at-least your manners), then the reply from the receiver , that will indicate you, whether you should proceed with asking time or not.
Same is the procedure in computer networks except that here the messages are exchanged between systems and machines and their hardware and software. The requesting node will send a requesting message to the receiver, then receiver will send a reply message, whether he is ready to communicate or not, and the communication will move on. This is often called as a 3-way handshake, that we will discuss in later articles. The figure below will make you understand this more clearly.

This whole procedure is governed by certain set of rules , that are called as protocols.

Ques 3. What are the different ways of sending data ?
The message or the data is called as packet in computer networks. So sending of packets can be done be done in 2 ways. Circuit switching and Packet Switching.

Ques 4. What are protocols?

A protocol defines the type, method and the order of the messages exchanged between the sender and the receiver node, and the actions to be taken after the transmission or the receipt of the message.
Ques 5. What are the problems that occur after setting up a network?

There are certain problems that we have to take into account to have proper transmission of message from sender to receiver. There can be Noise, various delays while transmitting, interference from outside etc.
Ques 6. How many protocol Layering are there?
There are basically two models of protocol layering .One is said to be Open Systems Interconnection(OSI ) layer model and the other is TCP/IP model.
In OSI model, there are 7 layers while in TCP/IP model, there are 5 layers of protocols.
Ques 7. Is there any threat to our networks to our hosts?

Yes, there are lots of threats engaged when you are connected to an Internet. There are two types of attacks, Active and Passive attacks. These attacks can include Denial of Service attacks, virus attacks, infrastructure attacks etc.


OSI App

The Top Most Layer : Application Layer

The Application Layer is the 1st layer in the TCP/IP stack according to Top-Down Approach. The Computer Applications are the main reason behind the existence of the computer networks. If there wouldn't have been any Application, then there was no need of any transport or networking protocol, that support these applications. After the Internet came into existence , number of useful , entertaining and applications have been developed and still the procedure is on.

Beginning from the text based applications, such as text mails, file transfers, further e-commerce websites and the world wide web. Now from the last couple of years , number of voice and video conferencing applications are developed. Such as , For android, there are two voice chat applications , We-chat and LINE. Video applications like Skype, Gmail video conferencing etc. are being developed.

There has been no slowing down of dashing and super applications to be developed. And I hope, you can also create a killer application for your future generation.

To begin with the further discussion , I want to tell you one more thing. Before developing an application, you should have a basic understanding that how the programs on the different hosts communicate with each other. In computer networks, its not the programs but the the processes that communicate with each other. A process can be termed as the subset of a program, that is running within a system. Processes on two different hosts communicate with each other by exchanging messages across the computer network. A sending process creates and sends messages into the network a receiving process receives these messages and responds by sending messages back. So you remember this, throughout your network study, that processes communicate. Two processes on same hosts communicate via Interprocess Communication. So now you are ready and we should move on.


Aspects of Network Applications:

Now you must also be thinking of developing a new application. Either the application is good for your country or is a video game for children. Whatever may be the reason or motivation behind your development. But there are many principles that you have to learn, in order to convert your idea into a real world application.
You have to develop an application that should run on different hosts and can interact with each other over the network. For Example: In Web applications, there are two processes that interact with each other. A Web Browser process running on the Client or user's side(can be a desktop, laptop or ipad) and a Web Browser process running on the on the Server side. 
Therefore, while developing a new application , you should always take into consideration, that it must be capable of running on multiple different hosts or end systems.

Architecture:

There are basically two Application architecture that you can use for communication between hosts. These are: Client-Server Architecture and Peer-to-Peer Architecture (P2P).

                  1. Client-Server Architecture


There is a always a server, which responds to requests from other hosts, called clients. For Example: The Web Application. In this this is a Web Sever that is always ON, that responds to request from browsers running on client systems. 
 Briefly we can say that, a process that initiates the communication is Client. The process that waits to be contacted is a Server.
introduction to application layer, server, client, client-server architecture, peer-2-peer architecture

Characteristics of Client-Server Architecture


1. Two clients never communicate directly with each other. For Example: Two browsers never communicate directly.
2. The Server has a well known address that is known as IP address in networking. The IP address of Server is always fixed. Because of this feature, the client can any-time contact the server by sending a packet to its IP address.
Some Examples of Client-Server Architecture Applications are E-mail, FTP, Telnet etc.


Problems with Client-Server Architecture


Many times, a single server is incapable of responding to all he requests of the clients. For Example: A Google server gets millions of requests every second, So its impossible for it to respond from a single system. To overcome this problem, the Data Center, combination of large number of hosts, is formed. Data Center is a virtual Server that is a combination of 1000's of servers that works as a single host. That's why they are called virtual server. Companies such as Yahoo, Google, Facebook have one or more data centers.


                  2. Peer-to-Peer Architecture (P2P)

In P2P Architecture, the end systems directly communicate with each other known as peers. Much of the Peers are not owned by the Service provide but, infact owned by the users. These peers can be at houses, offices or universities. Since the users communicate without passing by a dedicated sever, this called as P2P sharing. Examples of such Applications is Bit Torrent, that relies on the peers. Another example is Skype.
peer-2-peer architecture, computer networks, communication medium, direct interaction

Characteristics of P2P Architecture


It is self-scalable. As the users are directly communicating , so they don't have to depend on the server for space scalability and bandwidth. This is the most promising feature of P2P Architecture.

Problems with P2P Architecture


Security is the major drawback of this architecture. As there is no dedicated server for communications.

There is also a 3rd type of Architecture that is a combination of both Client-Server Architecture and P2P  Architecture. This is known as Hybrid Architecture. It is used in the cases, where you need the address of the two communicating hosts but after that, both the host will communicate each other. A very good example of this is Instant Messaging.


What you do in Instant Messaging is that you register yourself with a server. Like you register yourself with a website named Facebook. But after registering, you directly chat with your your friends and relatives. And they can reply you back. In such applications, the use of Hybrid Architecture is essential.******


  • Interaction Between Processes and Computer Networks

There are always two processes that are communicating with each other. Every process that wants to send message to other process has to send through the underlying network and underlying networking layers. A process sends and receive a message from the network through a device or a software, called as socket.


Let me give you an example , so you clearly understand what a socket is. 

Suppose you want to send a message to your friend ( say James). Here you are the process. Now what will you do. You will write a message and put into an envelope and will go and open the door, so that you should give this envelope to the postman who can deliver your envelope to your friend. Here your house door is the socket and the postman and the post-office are the underlying network and the networking layers. In the same way, the network will deliver the envelope to your friend , through his house door. There your friend is process and the door is socket.

Let me now try to explain it by drawing a figure.
process communication, socket, process, application developer, operating system, friend, destination address

As it is shown in the figure, the two processes communicating over the Internet. The Socket is the Interface between the Application Layer and the Underlying Transport layer, so it is also called as Application Programming Interface (API) . Since Socket is the API software with which the network applications are built. The Application developer has full control over the application side socket. But he doesn't have control over the transport layer side socket. On Transport Layer side socket, he can only control 2 things , that are
1. He can chose the type of protocol to be used, if choice is available and 2. He can set the maximum size of buffer or queue. And after choosing the protocol by the Application Developer, the Application is developed using the services provided by transport layer protocols.


How to Determine the Address of the Processes


If you want to send a parcel to someone, than that parcel should have your as well as the destination Address. In the same way, in computer networks, to send a packet to a host, the address of the destination host should be known. For identification of the receiving process, two things should be known. 1. Address of the host. 2. An identifier that specifies the receiving process in the destination host.
In Computer Networks, Inspite of having alphabetical addresses, hosts have IP address. I will tell you about IP address in detail in the coming posts. Till now, you should only remember that IP address is a 32-bit quantity that is a address of a host.Except the address of the host, the sending process should also know about the receiving process. Because in reality, there are many processes or applications running on a single host. For example, you could be running an email application , a Web application, a FTP application on your system. So to serve this purpose, PORT NUMBER is used. A particular port number is given to every application. For a Web application , port number 80 is assigned, for an email application , port number 25 is there. So these are the two basic things that a sender process should know about the receiver process.
You can found port numbers of different Internet Protocols by visiting this link. IANA
                                         


                                                       
This was all , I had with the Application Layer. Will meet you soon with the Application Layer Protocols.

Delays

DELAYS IN TRANSMISSION

All of us want Internet and its services to be able to move as much data as we want
between two end users or hosts, instantaneously and without any loss of data. Unfortunately, this
is just an imaginary perception that is cannot be done in reality. Infact computer networks necessarily
 introduce delays between hosts and can actually lose packets.

There are various types of delays in networks that occur due to various factors . These factors can be      

  •          Overhead in the communication link.
  •          The slow transmission rate of the link.
  •          Position of the hosts from each other.

 There are various reasons that account to the delays in the transmission of data in the network. So lets start  by looking at the delays and understanding them.

 1. Processing Delay (dproc):

Processing Delay is the time that is taken by the router to access the header of a packet and redirect it to the next path. This time is known as processing delay. Processing also include to check the next destination address of the packet as well as checking for any bit error in the packets, that can occur during transmission of the packet. Processing delay in high speed router is mostly in the order of microseconds. However it can be large, if the router is processing big encryption and decryption algorithms for processing packet header.

After all this processing , the router sends the packet to the queue that precedes the link to the next router( i.e. router B).


 2. Queuing Delay( dqueue):

Queuing Delay is the time that a packet has to wait in the queue before it can be transmitted over the link. Packets are put in the queue when the speed of incoming link to the router is faster than the outgoing link. Queuing delay depends on the number of earlier arrived packets already waiting for getting transmitted. If the queue is empty, then the queuing delay is zero, and if the traffic or the number of incoming packets is high, then the queuing delay is high. Queuing delay is mostly in order from microseconds to milliseconds.

Queuing Delay can be higher if the size of the queue or the buffer is very small.

 3. Transmission Delay( dtrans):

Transmission delay is usually caused by the data rate of the link. It is the time taken to push all the packet bits on to the link. For example : If the date rate of the link is 10 Mbps and your packet size 100 Kbps. Then the transmission Delay = 100 Kbps/10 Mbps = (100*1000)/ (10*1000000) = (1/100)seconds= .01 seconds.

As 1 Mbps = 1000000 bps       &    1 Kbps = 1000 bps.

To generalise this, if our packet is of M bits and link data rate is R bits/sec, then Transmission Delay = M/R seconds.

 4. Propagation Delay( dprop):

Propagation Delay is the time taken by the 1st bit of the packet to reach the receiver router. It can be calculated by dividing the distance between the two routers and the speed of propagation of the link.

For example:

d= distance between the routers
s=speed of propagation (almost equal to speed of light)

As the communication medium we use as copper wire or fibre optics, so in that propagation speed is equal to speed of light=3*(10^8) metres/second.

Propagation Delay = d/s


A delay for a packet at a router is said to be Nodal Delay (dnodal).

So the Nodal Delay is equal to the some of all the Delays for a packet.

                                         dnodal   =  dproc +  dqueue + dtrans+ dprop

Now , you should go through this Diagram, then you will be clear with all the Networking Delays.


Delays in computer networking, processing delay, transmission delay, propagation delay, queuing delay, nodal delay

Switching

Approaches for Moving Data In a Network

Till now we have discussed about the Basics of Computer Networks , Mediums to transfer Data and The Types of Delays in Computer Networks. In this post, I am going to tell you about the approaches or the techniques that are used for moving data in a Computer Network.

There are basically two approaches for moving data from Source host to the Destination Host. These are:
1. Circuit Switching
2. Packet Switching


CIRCUIT SWITCHING

In Circuit Switching, before the two hosts start communicating , the resources along the path are to be reserved, that are needed by the two hosts for their communication. The Resources are reserved for as long as the two hosts communicate.

Now I should give a live example that will make circuit switching clear to you.

Let us suppose that there are 2 restaurants A and B. In restaurant A, there is a need to reserve a table before going there for dinner or lunch. Whereas in restaurant B, there is no need for reservation. Now before going to restaurant A, you have to make a call and reserve a table but when you will arrive there, the table is set for you and you can directly be seated and order your meal. But in restaurant B, you need not bother to reserve a table, but when you arrive at the restaurant, you might have to wait for a table to get free before you can be seated.

In this restaurant analogy, restaurant A uses circuit switching for the customers.

circuit switched networks, minimal delay, resources reserved, telephones



A very classic example of circuit switching is your Landlines or telephones. When you make a call to your friend, a connection is established between both of you. And this connection remains open till the time you both are contacting and don't put your phone down. Since all the resources are reserved by you for that network, you can send and receive data at a very constant transmission rate.

Circuit Switched Networks are used for voice and video calls where any delay in the call can make a huge difference. Another example of circuit switched networks is Skype, for video calling.

Advantages of Circuit Switched Networks

1. Dedicated connection is established, the delays in the communication are very less or almost nil.

2. The quality of the connection or the call is very high.


Disadvantages of Circuit Switched Networks

       1. Now say, on telephone you talk to your friend for 15 min. But between these 15 min. , you remain quiet for 5 min., while still holding the phone in your hand. Thus, for those 5 min., the resources are misused and get wasted.
  
       2. It is not a good option for networks, where the traffic is very high. Because if two hosts reserve the resources, the other hosts have to wait for that period to leave those resources. Resulting in huge delays. In simple words, we can say that, circuit switching is not suitable for bursty traffic networks.

  • For circuit switched networks, there are various multiplexing techniques that are being used, in order to increase bandwidth utilisation. I will tell you about the different multiplexing techniques in the later posts.


PACKET SWITCHING
In Packet Switching, instead of reserving the resources, the packets are being send on the demand phenomenon. For example, if a host A has to send a packet to host B through a communication link or router, but that link is over-flow or is full, then the packet has to wait in the queue, to get transmitted.
Packet Switching is a dynamic phenomenon, that uses the resources only when needed.
packet switched networks, optimum bandwidth utilisation,  no resource wasted,


Advantages of Packet Switching

The resources or the bandwidth is optimally utilised without any wastage.

Disadvantages of Packet Switching

       1.The packets can arrive in a wrong order as they were sent.
        
       2. The delays between different packet can be different, resulting in degradation of the service provided.

Therefore, it all depends on the Application Developer, which Switching technique he wants to use. In today's Internet, as the Traffic is so huge, so Packet Switching is used in Internet Services.