Tuesday, January 02, 2007

HTTP Analogy

Imagine a small city with well developed roads and all houses connected to it. There is a very good bus service to take people around the city.
The internet broadband cables are the roads in the city. Each house is a computer and the address of the house is the IP address. The house can recieve and send mail. To establish a mail exchange they follow a rule in a particular sequence. House A looks for a House B and asks him if he would like to chat. If House B accepts then the enter into a exclusive one to one seesion and continue there mail exchange. This is TCP/IP.
Sometimes House A just wants to drop a message to House B and does not want to get into a converstaion. In this case he just writes down the address of House B and sends the package. House B decides to keep or discard it. This is UDP.
Now there is another House called 'WEB'. It stores lot of information about the world. House A wants to get some information from there and read it as he is reading a book. So House A opens up his browser(like internet explorer) and types in the address of House WEB. The browser which is like a page of your book now uses another set of rules to communicate with House WEB. This is called HTTP. HTTP rides over TCP/IP. HTTP uses lot of single sessions to communicate and once the answer to your query is got the conncetion is dropped. Every time you click on a link you send a HTTP request query to the House WEB. It is like a bus leaves your house everytime you click on a link. The passengers in the bus have this message for ex "Take me to ABCD restaurant". House WEB sees this message and fills in the address of ABCD restaurant in the BUS and sends it back to House A. Now the bus service has terminated and this was a single session. The format of the message returned from House WEB can be of different types. So they use a format called MIME(Multiple internet mail exchange). So for example if the address to the restaurant returned by the House WEB is a picture format, then this format is registered and sent to House A so that he know to open up a picture viewer to see the data.
House WEB can be providing lot of services, web server(HTTP request) may be one of them. So to keep each service separate it has a separate door for each of them. These doors are called ports and each a fixed number. For HTTP we have port number 80 as the default door number.