Introduction To Application Layer

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 51

INTRODUCTION TO APPLICATION LAYER:

INTRODUCTION:
The application layer provides services to the user.
Communication is provided using a logical connection,
which means that the two application layers assume that
there is an imaginary direct connection through which
they can send and receive messages.
The protocols in this layer do not provide services to any
other protocol in the suite; they only receive services
from the protocols in the transport layer. This means
that protocols can be removed from this layer easily.
New protocols can be also added to this layer as long as
the new protocols can use the services provided by one
of the transport-layer protocols.
Standard and Nonstandard Protocols:
To provide smooth operation of the Internet, the protocols used in
the first four layers of the TCP/IP suite need to be standardized
and documented 
• Standard Application-Layer Protocols:
There are several application-layer protocols that have been
standardized and documented by the Internet authority, and we
are using them in our daily interaction with the Internet.
Each standard protocol is a pair of computer programs that
interact with the user and the transport layer to provide a
specific service to the user.
. Nonstandard Application-Layer Protocols:
A programmer can create a nonstandard application-layer
program if she can write two programs that provide service to the
user by interacting with the transport layer.
Application-Layer Paradigms:
Using internet two application programs interact with
each other: one running on a computer somewhere in
the world, the other running on another computer
somewhere else in the world
And both application programs be able to request
services and provide services.
There are two Application layer paradigms have been
developed.
client-server paradigm and
peer-to-peer paradigm.

 
• Traditional Paradigm: Client-Server:
In this there are two processes
1. Server process
2. Client process
In this paradigm,
There are normally some server processes that can
provide a specific type of service, but there are many
clients that request service from any of these server
processes.
The server process must be running all the time; the
client process is started when the client needs to
receive service
New Paradigm: Peer-to-Peer:
• In this paradigm, there is no need for a server
process to be running all the time and waiting
for the client processes to connect. The
responsibility is shared between peers.
 
• A computer connected to the Internet can
provide service at one time and receive
service at another time. A computer can even
provide and receive services at the same time.
CLIENT-SERVER PROGRAMMING:
• In a client-server paradigm, communication at the application layer
is between two running application programs called processes: a
client and a server.
• A client is a running program that initializes the communication by
sending a request; a server is another application program that
waits for a request from a client.
• The server handles the request received from a client, prepares a
result, and sends the result back to the client. This definition of a
server implies that a server must be running when a request from a
client arrives, but the client needs to be run only when it is needed.
• This means that if we have two computers connected to each other
somewhere, we can run a client process on one of them and the
server on the other. However, we need to be careful that the server
program is started before we start running the client program. 
Application Programming Interface:
If we need a process to be able to communicate
with another process, we need a new set of
instructions to tell the lowest four layers of the
TCP/IP suite to
• open the connection,
• send and receive data from the other end,
close the connection.
A set of instructions of this kind is normally
referred to as an application programming
interface (API).
Several APIs have been designed for communication. One of the
most common one is: socket interface.
The socket interface is a set of instructions that provide
communication between the application layer and the operating
system, as shown in Figure

Position Of The Socket Interface


• The idea of sockets allows us to use the set of all
instructions already designed in a programming language
for other sources(for ex. Key board) and sinks(for ex:
monitor).
Sockets:
• It is an object that is created and used by the application
program.
Socket Addresses:
Since communication in the client-server paradigm is
between two sockets, we need a pair of socket
addresses for communication:
a local socket address and
a remote socket address  
Server Site: The server needs a local (server) and a
remote (client) socket address for communication
Local Socket Address The local (server) socket address is
provided by the operating system. The operating system
knows the IP address of the computer on which the
server process is running.
The port number of a server process, however, needs to
be assigned.
• If the server process is a standard one defined by the
Internet authority, a port number is already assigned to
it. For example, the assigned port number for a
Hypertext Transfer Protocol (HTTP) is the integer 80,
which cannot be used by any other process
Remote Socket Address The remote socket address for a
server is the socket address of the client that makes the
connection
The server can find this socket address when a client tries
to connect to the server.
Client Site: The client also needs a local (client) and a
remote (server) socket address for communication.
The local (client) socket address is also provided by the
operating system. The operating system knows the IP
address of the computer on which the client is running.
The port number, however, is a 16-bit temporary
integer that is assigned to a client process each time
the process needs to start the communication.
Remote Socket Address Finding the remote
(server) socket address for a client, however,
needs more work. When a client process
starts, it should know the socket address of
the server it wants to connect to.
•  
server code (Server.java):
• import java.lang.*; import java.io.*; import java.net.*;
• class Server {
• public static void main(String args[]) {
• String data = "Toobie ornaught toobie";
try {
ServerSocket srvr = new ServerSocket(1234);
Socket skt = srvr.accept(); System.out.print("Server has connected!\n");
PrintWriter out = new PrintWriter(skt.getOutputStream(), true);
System.out.print("Sending string: '" + data + "'\n"); out.print(data);
out.close();
skt.close();
srvr.close(); }
catch(Exception e) {
System.out.print("Whoops! It didn't work!\n");
}
}
}
• client code (Client.java):
• import java.lang.*; import java.io.*; import java.net.*;
class Client {
public static void main(String args[]) {
try {
Socket skt = new Socket("localhost", 1234); BufferedReader in =
new BufferedReader(new
InputStreamReader(skt.getInputStream()));
System.out.print("Received string: '");
while (!in.ready()) {}
System.out.println(in.readLine()); // Read one line and output it
System.out.print("'\n");
in.close(); }
catch(Exception e) {
System.out.print("Whoops! It didn't work!\n"); } } }
WORLD WIDE WEB AND HTTP:
• World Wide Web:
• The Web is a repository of information in which the
documents, called web pages, are distributed all over
the world and related documents are linked together.
• The popularity and growth of the Web can be related
to two terms distributed and linked.
Distribution allows the growth of the Web. Each web
server in the world can add a new web page to the
repository and announce it to all Internet users
without overloading a few servers.
Linking allows one web page to refer to another web page
Architecture:
• The WWW today is a distributed client-server
service, in which a client using a browser can
access a service using a server. However, the
service provided is distributed over many
locations called sites.
• Each site holds one or more web pages.
• Each web page, however, can contain some
links to other web pages in the same or other
sites
Web Client (Browser): A variety of vendors offer
commercial browsers that interpret and
display a web page
Each browser usually consists of three parts:
• a controller,
• client protocols
• Interpreters
• The controller receives input from the keyboard or
the mouse and uses the client programs to access
the document. After the document has been
accessed, the controller uses one of the interpreters
to display the document on the screen.
• The client protocol can be one of the protocols
described later, such as HTTP or FTP.
• The interpreter can be HTML, Java, or JavaScript,
depending on the type of document.
• Some commercial browsers include Internet
Explorer, Netscape Navigator, and Firefox.
Web Server: The web page is stored at the
server. Each time a request arrives, the
corresponding document is sent to the client.
Uniform Resource Locator (URL):
• A web page, as a file, needs to have a unique
identifier to distinguish it from other web
pages. To define a web page, we need three
identifiers: host, port, and path.
• Protocol. Is the first identifier used by client-server program in order to
access the web page.
For ex: HTTP (HyperText Transfer Protocol) and FTP (File Transfer
Protocol).
• Host. The host identifier can be the IP address of the server or the unique
name given to the server. IP addresses can be defined in dotted decimal
notation.
• Port. The port, a 16-bit integer, is normally predefined for the client-server
application.
• Path. The path identifies the location and the name of the file in the
underlying operating system. The format of this identifier normally
depends on the operating system.
• To combine these four pieces together, the uniform resource locator
(URL) has been designed; it uses three different separators between the
four pieces as shown below:
Web Documents:
The documents in the WWW can be grouped into
three broad categories: static, dynamic, and active
Static documents are fixed-content documents that
are created and stored in a server. The client can
get a copy of the document only.
Static documents are prepared using one of several
languages: HyperText Markup Language (HTML),
Extensible Markup Language (XML), Extensible
Style Language (XSL), and Extensible Hypertext
Markup Language (XHTML).
Dynamic Documents:
• A dynamic document is created by a web server whenever a
browser requests the document.
• When a request arrives, the web server runs an application
program or a script that creates the dynamic document.
• The server returns the result of the program or script as a
response to the browser that requested the document.
Because a fresh document is created for each request, the
contents of a dynamic document may vary from one request
to another. A very simple example of a dynamic document
is the retrieval of the time and date from a server.
•  
• Active Documents:
For many applications, we need a program or
a script to be run at the client site. These are
called active documents.
For example, suppose we want to run a program
that creates animated graphics on the screen
or a program that interacts with the user
HyperText Transfer Protocol (HTTP):
• The HyperText Transfer Protocol (HTTP) is used
to define how the client-server programs can
be written to retrieve web pages from the Web.
• An HTTP client sends a request; an HTTP server
returns a response. The server uses the port
number 80; the client uses a temporary port
number.
• HTTP uses the services of TCP, which, as
discussed before, is a connection-oriented and
reliable protocol.
Non persistent versus Persistent Connections:
Non persistent Connections
In a nonpersistent connection, one TCP connection is made for
each request/response.
The following lists the steps in this strategy:
•  The client opens a TCP connection and sends a request.
•  The server sends the response and closes the connection.
•  The client reads the data until it encounters an end-of-file marker;
it then closes the connection.
 Persistent Connections
 HTTP version 1.1 specifies a persistent connection by default. In a
persistent connection, the server leaves the connection open for
more requests after sending a response.
 
Message Formats:
The HTTP protocol defines the format of the request and
response messages. Each message is made of four sections.
The first section in the request message is called the request
line; the first section in the response message is called the
status line.
 
The other three sections have the same names in the request
and response messages. However, the similarities between
these sections are only in the names; they may have
different contents. We discuss each message type
separately.
 
Request Message:
 There are three fields in the request message. The
fields are called method, URL, and version.
 The method field defines the request types.
Several methods are defined like GET, PUT, HEAD,
POST, TRACE, DELETE, etc.
The URL defines the address and name of the
corresponding web page.
The version field gives the version of the protocol;
the most current version of HTTP is 1.1.
 
Response Message:
 A response message consists of a status line, header lines, a blank line,
and sometimes a body.
The first line in a response message is called the status line.
There are three fields in this status line
 The first field defines the version of HTTP protocol, currently 1.1.
The second field is status code defines the status of the request. It consists
of three digits. Whereas the codes in the 100 range are only
informational, the codes in the 200 range indicate a successful request.
 The codes in the 300 range redirect the client to another URL, and the
codes in the 400 range indicate an error at the client site. Finally, the
codes in the 500 range indicate an error at the server site.
 The third field is status phrase explains the status code in text form. After
the status line, we can have zero or more response header lines. Each
header line sends additional information from the server to the client.
Web Caching: Proxy Servers:
HTTP supports proxy servers. A proxy server is a computer that
keeps copies of responses to recent requests. The HTTP client
sends a request to the proxy server. The proxy server checks its
cache.
 
If the response is not stored in the cache, the proxy server sends
the request to the corresponding server. Incoming responses are
sent to the proxy server and stored for future requests from
other clients.
 
The proxy server reduces the load on the original server, decreases
traffic, and improves latency. However, to use the proxy server,
the client must be configured to access the proxy instead of the
target server.
HTTP Security:
 HTTP it self not provide security.
HTTP can be run over the Secure Socket Layer
(SSL). In this case, HTTP is referred to as
HTTPS.
HTTPS provides confidentiality, client and
server authentication, and data integrity.
 
FTP:
File Transfer Protocol (FTP) is the standard protocol
provided by TCP/IP for copying a file from one host to
another
the basic model of FTP. :
The client has three components:
• user interface,
• client control process
• client data transfer process.
The server has two components:
• server control process
• server data transfer process
• The control connection is made between the control
processes.
• The data connection is made between the data
transfer processes.
• Separation of commands and data transfer makes
FTP more efficient.
• The control connection uses very simple rules of
communication. We need to transfer only a line of
command or a line of response at a time.
• The data connection, on the other hand, needs
more complex rules due to the variety of data types
transferred.
Two Connections
 The two connections in FTP have different
lifetimes.
The control connection remains connected
during the entire interactive FTP session.
The data connection is opened and then closed
for each file transfer activity.
 FTP uses two well-known TCP ports: port 21 is
used for the control connection, and port 20 is
used for the data connection.
Control Connection:
During this control connection, commands are
sent from the client to the server and
responses are sent from the server to the
client.
Every FTP command generates at least one response.
A response has two parts:
a three-digit number followed by text. The numeric
part defines the code;
the text part defines needed parameters or further
explanations.

Code Description Code Description


Data Connection
125 Open 250 Request file action OK
User name OK; password
150 File Status OK 331 is needed
Cannot open data
200 Command OK 425 connection
ELECTRONIC MAIL:
Electronic mail (or e-mail) allows users to
exchange messages.
In an application such as HTTP or FTP, the server
program is running all the time but In the case
of electronic mail, the situation is different. First,
e-mail is considered a one-way transaction
This means that the idea of client/server
programming should be implemented in
another way: using some intermediate
computers (servers). The users run only client
programs when they want and the intermediate
servers apply the client/server paradigm
Architecture:
A simple e-mail from Alice to Bob takes nine
different steps.
Alice and Bob use three different agents:
a user agent (UA),
a message transfer agent (MTA),
a message access agent (MAA).
When Alice needs to send a message to Bob, she
runs a UA program to prepare the message
and send it to her mail server.
The mail server at her site uses a queue (spool)
to store messages waiting to be sent.
The message, however, needs to be sent
through the Internet from Alice’s site to Bob’s
site using an MTA. Here two message transfer
agents are needed: one client and one server.
The user agent at the Bob site allows Bob to
read the received message. Bob later uses an
MAA client to retrieve the message from an
MAA server running on the second server.
User Agent: A user agent is a software package
(program) that composes, reads, replies to, and
forwards messages. It also handles local mailboxes
on the user computers.
Message Transfer Agent(MTA): SMTP:
• The formal protocol that defines the MTA client
and server in the Internet is called Simple Mail
Transfer Protocol (SMTP).
• SMTP is used two times, between the sender and
the sender’s mail server and between the two mail
servers. SMTP simply defines how commands and
responses must be sent back and forth.
Message Access Agent: POP and IMAP:
this stage needs a pull protocol; the client must
pull messages from the server. The direction of
the bulk data is from the server to the client. The
third stage uses a message access agent
Currently two message access protocols are
available:
Post Office Protocol, version 3 (POP3) and
Internet Mail Access Protocol, version 4 (IMAP4).
 
POP3:
 Post Office Protocol, version 3 (POP3)
The client POP3 software is installed on the recipient computer;
the server POP3 software is installed on the mail server.
 Mail access starts with the client when the user needs to
download its e-mail from the mailbox on the mail server.
The client opens a connection to the server on TCP using port
110. It then sends its user name and password to access the
mailbox. The user can then list and retrieve the mail messages,
one by one.
 POP3 has two modes: the delete mode and the keep mode. In
the delete mode, the mail is deleted from the mailbox after
each retrieval. In the keep mode, the mail remains in the
mailbox after retrieval.
IMAP4:
Another mail access protocol is Internet Mail Access Protocol, version 4
(IMAP4). IMAP4 is similar to POP3, but it has more features; IMAP4 is more
powerful and more complex.
 POP3 is deficient in several ways.
 It does not allow the user to organize her mail on the server;
 the user cannot have different folders on the server. In addition,
 POP3 does not allow the user to partially check the contents of the mail
before downloading.
 IMAP4 provides the following extra functions:
  A user can check the e-mail header prior to downloading.
 A user can search the contents of the e-mail for a specific string of characters
prior to downloading.
 A user can partially download e-mail. This is especially useful if bandwidth is
limited and the e-mail contains multimedia with high bandwidth
requirements.
 A user can create, delete, or rename mailboxes on the mail server.
TELNET:
allows a user on the client site to log into the
computer at the server site and use the
services available there and it is called Remote
Logging.
. Although TELNET requires a logging name and
password, it is vulnerable to hacking because
it sends all data including the password in
plaintext (not encrypted). So we move
towards the Secure Shell(SSH).
Although TELNET is almost replaced by SSH, we
briefly discuss TELNET here for two reasons:
•  The simple plaintext architecture of TELNET
allows us to explain the issues and challenges
related to the concept of remote logging,
which is also used in SSH when it serves as a
remote logging protocol.
• Network administrators often use TELNET for
diagnostic and debugging purposes
Local versus Remote Logging:
When a user logs into a local system, it is called
local logging.
As a user types at a terminal the keystrokes are
accepted by the terminal driver.
• The terminal driver passes the characters to
the operating system.
• The operating system, in turn, interprets the
combination of characters and invokes the
desired application program or utility.
• However, when a user wants to access an application program or
utility located on a remote machine, she performs remote logging.
• Here the TELNET client and server programs come into use.
• The user sends the keystrokes to the terminal driver where the
local operating system accepts the characters but does not
interpret them.
• The characters are sent to the TELNET client, which transforms
the characters into a universal character set called Network
Virtual Terminal (NVT) characters and delivers them to the local
TCP/IP stack.
• The commands or text, in NVT form, travel through the Internet
and arrive at the TCP/IP stack at the remote machine. Here the
characters are delivered to the operating system and passed to the
TELNET server, which changes the characters to the corresponding
characters understandable by the remote computer.
• However, the characters cannot be passed
directly to the operating system because the
remote operating system is not designed to
receive characters from a TELNET server; it is
designed to receive characters from a terminal
driver.
• The solution is to add a piece of software called
a pseudoterminal driver, which pretends that
the characters are coming from a terminal. The
operating system then passes the characters to
the appropriate application program.
Options: TELNET lets the client and server negotiate options
before or during the use of the service.
 User Interface:
 The operating system (UNIX, for example) defines an interface
with user-friendly commands. An example of such a set of
commands can be found in Table below:
 
Command Name Meaning
Open Connect to a remote computer
Close Close the connections

Display Show the operating parameters


Mode Change to line or character mode

Quit Exit TELNET

Send Send special characters

You might also like