PART 6 Application Layer Kyung Hee University 1

  • Slides: 53
Download presentation
PART 6 Application Layer Kyung Hee University 1

PART 6 Application Layer Kyung Hee University 1

Position of Application Layer q Kyung Hee University 2

Position of Application Layer q Kyung Hee University 2

Role of Application Layer q Enables the user, whether human or software, to access

Role of Application Layer q Enables the user, whether human or software, to access the network q Provides user interfaces and support for services such as electronic mail, remote file access and transfer, and access to the World Wide Web Kyung Hee University 3

General Issues of Application Layer q Client-server Paradigm Kyung Hee University 4

General Issues of Application Layer q Client-server Paradigm Kyung Hee University 4

General Issues of Application Layer q Addressing Email address to access a web page

General Issues of Application Layer q Addressing Email address to access a web page q Types of Service Application layer is designed to give different services to the user or user programs. Kyung Hee University l SMTP l FTP l WWW l HTTP 5

Chapter 27 HTTP and WWW Kyung Hee University 6

Chapter 27 HTTP and WWW Kyung Hee University 6

27. 1 HTTP q HTTP is used mainly to access data on the WWW

27. 1 HTTP q 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. q 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. l SMTP messages are stored and forward, but HTTP messages are delivered immediately q HTTP uses the services of TCP on well-known port 80 Kyung Hee University 7

About SMTP q Architecture of Simple Mail Transfer Protocol (SMTP) Kyung Hee University 8

About SMTP q Architecture of Simple Mail Transfer Protocol (SMTP) Kyung Hee University 8

HTTP (cont’d) q The request and response messages carry data in the form of

HTTP (cont’d) q 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 q 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. Kyung Hee University 9

HTTP (cont’d) q HTTP Transaction Kyung Hee University 10

HTTP (cont’d) q HTTP Transaction Kyung Hee University 10

HTTP (cont’d) q Request Messages Kyung Hee University 11

HTTP (cont’d) q Request Messages Kyung Hee University 11

HTTP (cont’d) q Request line Request type : categorizing the request messages into several

HTTP (cont’d) q Request line Request type : categorizing the request messages into several methods URL defines four things : method, host computer, port and path Kyung Hee University 12

HTTP (cont’d) l The method is the protocol used to retrieve the document –

HTTP (cont’d) l The method is the protocol used to retrieve the document – l The host is the computer where the information is located l The port number of the server is optional. l l Kyung Hee University ex) FTP, HTTP Path is the path name of the file where the information is located. Version of HTTP 13

HTTP (cont’d) Methods l GET, HEAD, POST, PUSH, etc. q Response Message Kyung Hee

HTTP (cont’d) Methods l GET, HEAD, POST, PUSH, etc. q Response Message Kyung Hee University 14

HTTP (cont’d) Status line l l Kyung Hee University Status code field is similar

HTTP (cont’d) Status line l l Kyung Hee University Status code field is similar to those in the FTP and the SMTP Status phrase : explain the status code in text form 15

HTTP (cont’d) q Headers Header format Kyung Hee University 16

HTTP (cont’d) q Headers Header format Kyung Hee University 16

HTTP (cont’d) q General Header : gives general information about the messages q Request

HTTP (cont’d) q General Header : gives general information about the messages q Request Header : specifies the server’s configuration and special information about the request q Response Header : specifies the server’s configuration and special information about the request q Entity Header : gives information about the body of the document Kyung Hee University 17

Example 1 q. This example retrieves a document. We use the GET method to

Example 1 q. This example retrieves a document. We use the GET method to retrieve an image with the path /usr/bin/image 1. 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). Kyung Hee University 18

Example 1 (cont’d) Kyung Hee University 19

Example 1 (cont’d) Kyung Hee University 19

Example 2 q This example retrieves information about a document. We use the HEAD

Example 2 q 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 Kyung Hee University 20

Example 2 (cont’d) Kyung Hee University 21

Example 2 (cont’d) Kyung Hee University 21

HTTP (cont’d) – Some Other Features q Nonpersistent Connection 1. The client opens a

HTTP (cont’d) – Some Other Features q Nonpersistent Connection 1. The client opens a TCP connection 2. The server sends the response and closes the connection 3. The client reads the data until it encounters an end-offile marker q Persistent connection The server leaves the connection open for more request after sending a response q HTTP version 1. 1 specifies a persistent connection by default. Kyung Hee University 22

HTTP (cont’d) q Proxy server HTTP supports proxy servers A proxy server is a

HTTP (cont’d) q 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 Kyung Hee University 23

World Wide Web (WWW) q A repository of information spread all over the world

World Wide Web (WWW) q A repository of information spread all over the world and linked together. q The WWW project was initiated by CERN (European Laboratory for Particle Physics) to create a system to handle distributed resources necessary for scientific research. q The WWW today is a distributed client-sever service, in which a client using a browser can access a service using a server Kyung Hee University 24

WWW (cont’d) q The service provided is distributed over many locations called websites. q

WWW (cont’d) q The service provided is distributed over many locations called websites. q Distributed Services Kyung Hee University 25

WWW (cont’d) q Hypertext q Hypermedia documents - including pictures, graphics and sound Kyung

WWW (cont’d) q Hypertext q Hypermedia documents - including pictures, graphics and sound Kyung Hee University 26

WWW (cont’d) q Browser architecture Kyung Hee University 27

WWW (cont’d) q Browser architecture Kyung Hee University 27

WWW (cont’d) q Categories of Web documents Static documents are fixed-content document that are

WWW (cont’d) q 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. Kyung Hee University 28

WWW (cont’d) q Static document Kyung Hee University 29

WWW (cont’d) q Static document Kyung Hee University 29

WWW (cont’d) q HTML (Hypertext Markup Language) - is a language for creating Web

WWW (cont’d) q HTML (Hypertext Markup Language) - is a language for creating Web services Kyung Hee University 30

WWW (cont’d) q Effect of boldface tags Kyung Hee University 31

WWW (cont’d) q Effect of boldface tags Kyung Hee University 31

WWW (cont’d) q Beginning and ending tag = Kyung Hee University = 32

WWW (cont’d) q Beginning and ending tag = Kyung Hee University = 32

WWW (cont’d) q Common tags Beginning Tag Ending Tag Meaning Skeletal Tags <HTML> </HTML>

WWW (cont’d) q Common tags Beginning Tag Ending Tag Meaning Skeletal Tags <HTML> </HTML> Defines an HTML document <HEAD> </HEAD> Defines the head of the document <BODY> </BODY> Defines the body of the document Title and Header Tags <TITLE> </TITLE> Defines the title of the document <Hn> </Hn> Defines the title of the document Kyung Hee University 33

WWW (cont’d) q Common tags Beginning Tag Ending Tag Meaning Text Formatting Tags <B>

WWW (cont’d) q Common tags Beginning Tag Ending Tag Meaning Text Formatting Tags <B> </B> Boldface <I> </I> Italic <U> </U> Underlined <SUB> </SUB> Subscript <SUP> </SUP> Superscript Data Flow Tag <CENTER> </CENTER> <BR> </BR> Kyung Hee University Centered Line break 34

WWW (cont’d) Beginning Tag Ending Tag Meaning List Tags <OL> </OL> Ordered list <UL>

WWW (cont’d) Beginning Tag Ending Tag Meaning List Tags <OL> </OL> Ordered list <UL> </UL> Unordered list <LI> </LI> An item in a list Image Tag <IMG> Defines an image Hyperlink Tag <A> </A> Defines an address (hyperlink) Executable Contents <APPLET> Kyung Hee University </APPLET> The document is an applet 35

Example 3 q This example shows how tags are used to let the browser

Example 3 q 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> <H 1><B> ATTENTION </B></H 1> </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> Kyung Hee </HTML> University 36

Example 4 q This example shows how tags are used to import an image

Example 4 q 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/book 1. gif" ALIGN=MIDDLE> </BODY> </HTML> Kyung Hee University 37

Example 5 q This example shows how tags are used to make a hyperlink

Example 5 q 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> Kyung Hee University 38

WWW (cont’d) q Dynamic document does not exist in a predefined format. is created

WWW (cont’d) q Dynamic document does not exist in a predefined format. is created by a Web server whenever a browser requests the document. Kyung Hee University 39

WWW (cont’d) q Common Gateway Interface is a technology that creates and handles dynamic

WWW (cont’d) q Common Gateway Interface is a technology that creates and handles dynamic documents CGI program ~ is code written in one the languages supporting CGI Kyung Hee University 40

WWW (cont’d) q Example 6 is a CGI program written in Bourne shell script.

WWW (cont’d) q 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 program echo Content_type: text/plain echo # The body of the program now='date' echo $now exit 0 Kyung Hee University 41

Example 7 q Example 7 is similar to Example 6 except that program output

Example 7 q Example 7 is similar to Example 6 except that program output is in HTML. #!/bin/sh # The head of the program echo Content_type: text/html echo # The body of the program echo <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 Kyung Hee University 42

Example 8 q Example 8 is similar to Example 7 except that the program

Example 8 q Example 8 is similar to Example 7 except that the program is written in Perl. #!/bin/perl # The head of the program print "Content_type: text/htmln"; print "n"; # The body of the program print "<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 Kyung Hee University 43

WWW (cont’d) q Active Documents For many applications, we need a program to be

WWW (cont’d) q Active Documents For many applications, we need a program to be run at the client site. l Kyung Hee University These are called active documents 44

Example 9 q JAVA Skeleton of an Applet Kyung Hee University 45

Example 9 q JAVA Skeleton of an Applet Kyung Hee University 45

WWW (cont’d) q Installation of the object defined by an applet. Kyung Hee University

WWW (cont’d) q Installation of the object defined by an applet. Kyung Hee University 46

WWW (cont’d) q Creation and compilation Kyung Hee University 47

WWW (cont’d) q Creation and compilation Kyung Hee University 47

WWW (cont’d) q HTML document carrying an applet = = = Kyung Hee University

WWW (cont’d) q HTML document carrying an applet = = = Kyung Hee University 48

Example 9 q In this example, we first import two packages, java. awt and

Example 9 q 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 draw. String, which is defined in java. awt. *. Kyung Hee University 49

Example 9 First Example of Java import java. applet. *; import 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. draw. String ("Hello World", 100); } } Kyung Hee University 50

Example 10 q In this example, we modify the program in Example 9 to

Example 10 q In this example, we modify the program in Example 9 to draw a line. Instead of method draw. String, we use another method called draw. Line. This method needs four parameters: the x and y coordinates at the beginning of the line and the x and y coordinates at the end of the line. We use 0, 0 for the beginning and 80, 90 for the end. Kyung Hee University 51

Example 10 q Second example of Java import java. applet. *; import java. awt.

Example 10 q Second example of Java import java. applet. *; import java. awt. *; public class Second extends Applet { public void paint (Graphics g) { g. draw. Line (0, 0, 80, 90); } } Kyung Hee University 52

Thanks ! Kyung Hee University 53

Thanks ! Kyung Hee University 53