530 likes | 561 Views
PART 6 Application Layer. Position of Application Layer. Role of Application Layer. Enables the user, whether human or software, to access the network
E N D
Role of Application Layer • Enables the user, whether human or software, to access the network • Provides user interfaces and support for services such as electronic mail, remote file access and transfer, and access to the World Wide Web
General Issues of Application Layer • Client-server Paradigm
General Issues of Application Layer • Addressing • Email address • address to access a web page • Types of Service • Application layer is designed to give different services to the user or user programs. • SMTP • FTP • WWW • HTTP
27.1 HTTP • HTTP is used mainly to access data on the WWW • The protocol transfers data in the form of plain text, hypertext, audio, video, and so on. • HTTP functions like a combination of FTP and SMTP. • HTTP is much simpler than FTP because it uses only one TCP connection (well-known port 80) • HTTP is like SMTP because the data transferred between the client and the server are similar to SMTP messages. • SMTP messages are stored and forward, but HTTP messages are delivered immediately • HTTP uses the services of TCP on well-known port 80
About SMTP • Architecture of Simple Mail Transfer Protocol (SMTP)
HTTP (cont’d) • The request and response messages carry data in the form of a letter with a MIME-like format. • letter-like request and letter-like response messages * MIME :Multipurpose Internet Mail Extensions • Transaction • HTTP is stateless protocol; Each time you need something from the server, your client (browser) makes a connection, gets that file, and then the connection is closed. • The client initializes the transaction by sending a request message. • The sever replies by sending a response.
HTTP (cont’d) • HTTP Transaction
HTTP (cont’d) • Request Messages
HTTP (cont’d) • Request line • Request type : categorizing the request messages into several methods • URL defines four things : method, host computer, port and path
HTTP (cont’d) • The method is the protocol used to retrieve the document • ex) FTP, HTTP • The host is the computer where the information is located • The port number of the server is optional. • Path is the path name of the file where the information is located. • Version of HTTP
HTTP (cont’d) • Methods • GET, HEAD, POST, PUSH, etc. • Response Message
HTTP (cont’d) • Status line • Status code field is similar to those in the FTP and the SMTP • Status phrase : explain the status code in text form
HTTP (cont’d) • Headers • Header format
HTTP (cont’d) • General Header : gives general information about the messages • Request Header : specifies the server’s configuration and special information about the request • Response Header : specifies the server’s configuration and special information about the request • Entity Header : gives information about the body of the document
Example 1 • This example retrieves a document. We use the GET method to retrieve an image with the path /usr/bin/image1. The request line shows the method (GET), the URL, and the HTTP version (1.1). The header has two lines that show that the client can accept images in GIF and JPEG format. The request does not have a body. The response message contains the status line and four lines of header. The header lines define the date, server, MIME version, and length of the document. The body of the document follows the header (see Fig. 27.9, next slide).
Example 2 • This example retrieves information about a document. We use the HEAD method to retrieve information about an HTML document (see the next section). The request line shows the method (HEAD), URL, and HTTP version (1.1). The header is one line showing that the client can accept the document in any format (wild card). The request does not have a body. The response message contains the status line and five lines of header. The header lines define the date, server, MIME version, type of document, and length of the document (see Fig. 27.10, next slide). Note that the response message does not contain a body
HTTP (cont’d) – Some Other Features • Nonpersistent Connection • The client opens a TCP connection • The server sends the response and closes the connection • The client reads the data until it encounters an end-of-file marker • Persistent connection • The server leaves the connection open for more request after sending a response • HTTP version 1.1 specifies a persistent connection by default.
HTTP (cont’d) • Proxy server • HTTP supports proxy servers • A proxy server is a computer that keeps copies of response to recent requests • Reducing the load on the original sever, decreasing traffic, and improving latency
World Wide Web (WWW) • A repository of information spread all over the world and linked together. • The WWW project was initiated by CERN (European Laboratory for Particle Physics) to create a system to handle distributed resources necessary for scientific research. • The WWW today is a distributed client-sever service, in which a client using a browser can access a service using a server
WWW (cont’d) • The service provided is distributed over many locations called websites. • Distributed Services
WWW (cont’d) • Hypertext • Hypermedia documents - including pictures, graphics and sound
WWW (cont’d) • Browser architecture
WWW (cont’d) • Categories of Web documents • Static documents are fixed-content document that are created and stored in a server. The contents in the server can be changed, but the user cannot change it.
WWW (cont’d) • Static document
WWW (cont’d) • HTML (Hypertext Markup Language) - is a language for creating Web services
WWW (cont’d) • Effect of boldface tags
WWW (cont’d) • Beginning and ending tag = =
WWW (cont’d) • Common tags
WWW (cont’d) • Common tags
Example 3 • This example shows how tags are used to let the browser format the appearance of the text <HTML> <HEAD> <TITLE>First Sample Document</TITLE> </HEAD> <BODY> <CENTER> <H1><B>ATTENTION</B></H1> </CENTER> You can get a copy of this document by: <UL> <LI>Writing to the publisher <LI> Ordering online <LI> Ordering through a bookstore </UL> </BODY> </HTML>
Example 4 • This example shows how tags are used to import an image and insert it into the text <HTML> <HEAD> <TITLE>Second Sample Document</TITLE> </HEAD> <BODY> This is the picture of a book: <IMG SRC="Pictures/book1.gif" ALIGN=MIDDLE> </BODY> </HTML>
Example 5 • This example shows how tags are used to make a hyperlink to another document. <HTML> <HEAD> <TITLE> Third Sample Document </TITLE> </HEAD> <BODY> This is a wonderful product that can save you money and time. To get information about the producer, click on <A HREF="http://www.phony.producer"> Producer </A> </BODY> </HTML>
WWW (cont’d) • Dynamic document • does not exist in a predefined format. • is created by a Web server whenever a browser requests the document.
WWW (cont’d) • Common Gateway Interface • is a technology that creates and handles dynamic documents • CGI program ~ is code written in one the languages supporting CGI
WWW (cont’d) • Example 6 is a CGI program written in Bourne shell script. The program accesses the UNIX utility (date) that returns the date and the time. Note that the program output is in plain text. #!/bin/sh # The head of the programecho Content_type: text/plainecho# The body of the program now='date'echo $nowexit 0
Example 7 • Example 7 is similar to Example 6 except that program output is in HTML. #!/bin/sh # The head of the programecho Content_type: text/htmlecho# The body of the programecho <HTML>echo <HEAD><TITLE> Date and Time </TITLE></HEAD>echo <BODY>now='date'echo <CENTER><B> $now </B></CENTER>echo </BODY>echo </HTML>exit 0
Example 8 • Example 8 is similar to Example 7 except that the program is written in Perl. #!/bin/perl # The head of the programprint "Content_type: text/html\n";print "\n";# The body of the programprint "<HTML>\n";print "<HEAD><TITLE> Date and Time </TITLE></HEAD>\n";print "<BODY>\n";$now = 'date';print "<CENTER><B> $now </B></CENTER>\n";print "</BODY>\n";print "</HTML>\n";exit 0
WWW (cont’d) • Active Documents • For many applications, we need a program to be run at the client site. • These are called active documents
Example 9 • JAVA • Skeleton of an Applet
WWW (cont’d) • Installation of the object defined by an applet.
WWW (cont’d) • Creation and compilation
WWW (cont’d) • HTML document carrying an applet = = =
Example 9 • In this example, we first import two packages, java.awt and java.applet. They contain the declarations and definitions of classes and methods that we need. Our example uses only one publicly inherited class called First. We define only one public method, paint. The browser can access the instance of First through the public method paint. The paint method, however, calls another method called drawString, which is defined in java.awt.*.
Example 9 First Example of Java import java.applet.*;import java.awt.*;public class First extends Applet{ public void paint (Graphics g) { g.drawString ("Hello World", 100, 100); }}