CNW MOD2
CNW MOD2
APPLICATION LAYER
APPLICATION LAYER
• URL : https://www.javatpoint.com/url
1. https: protocol
2. javatpoint : domain web page
3. .com : stands for type of website
4. /url : path and name of accessing web page
HTTP
• HyperText Transfer Protocol is an application layer
protocol.
• It is implemented using client and server programs.
• Client and server program running in different end system
communicate using HTTP messages.
• Web browser is client side and web server is a server side.
• HTTP defines how web clients request web pages from
web servers and how server transfer web pages to clients.
• The browser sends HTTP request message to server and
server sends HTTP response message back to browser.
• HTTP uses TCP as its underlying transport protocol.
1. HTTP client initiates TCP connection with server.
2. Once connection established the client and server
processes access TCP through socket interfaces.
3. The client side sends HTTP request message through
socket interface and receive HTTP response message
through socket interface
4. The server side sends HTTP response message through
socket interface and receive HTTP request message
through socket interface
• Once client send request then TCP handles delivery. There
is no chances of data loss.
• Server sends requested files to client without storing any
state information about client.
• So if client sends request for same object twice within few
seconds the server doesnt send a message saying it just
serve the object now instead server responds again as it
has completely forgotten.
• Since HTTP server maintains no information about client it
is known as stateless protocol.
NonPersistent and Persistent Connections
•If the web pages, objects to be retrieved, are located on
different servers, create a new TCP connection for
retrieving each object.
•If some of the objects are located on the same server, we
have two choices:
• retrieve each object using a new TCP connection or
make a TCP connection and retrieve them all.
•The first method is referred to as nonpersistent
connections, the second as persistent connections.
NonPersistent Connections
cr - carraige
return
lf - line field
sp - space
Example
• GET /hello.htm HTTP/1.1
• User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows
NT)
• Host: www.tutorialspoint.com
• Accept-Language: en-us
• Accept-Encoding: gzip, deflate
• Connection: Keep-Alive
HTTP 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 line separated by spaces and
terminated by a carriage return and line feed.
•The first field defines the version of HTTP protocol, currently
1.1.
•The status code field defines the status of the request.
• It consists of three digits.
• The status phrase explains the status code in text form.
Status code
• 1xx: Informational :It means the request was received and
the process is continuing.
• 2xx: Success :It means the action was successfully
received, understood, and accepted.
• 3xx: Redirection: It means further action must be taken in
order to complete the request.
• 4xx: Client Error: It means the request contains incorrect
syntax or cannot be fulfilled.
• 5xx: Server Error:It means the server failed to fulfill an
apparently valid request.
Example
• HTTP/1.1 200 OK
• Date: Mon, 27 Jul 2009 12:28:53 GMT
• Server: Apache/2.2.14 (Win32)
• Last-Modified: Wed, 22 Jul 2009 19:15:56 GMT
• Content-Length: 88
• Content-Type: text/html
• Connection: Closed
• (data data data.....)
Cookies
•The World Wide Web was originally designed as a stateless entity.A
client sends a request; a server responds. Their relationship is over.
•Today the Web has other functions that need to remember some
information about the clients.Websites may allow access to
registered clients only.
•Cookies are HTTP messages that carry state and it permits sites to
learn about you.
•Cookie can be used for authorization,shopping carts,
recommendation,session state etc.
•When a server receives a request from a client, it stores
information about the client in a file or a string.
•The contents of the cookie (information the server has
gathered about the client such as name, registration number,
and so on), a timestamp, and other information depending on
the implementation.
•The server includes the cookie in the response that it sends
to the client.
•When the client receives the response, the browser stores the
cookie in the cookie directory, which is sorted by the server
domain name.
•When a client sends a request to a server, the browser looks
in the cookie directory to see if it can find a cookie sent by
that server.
• If found, the cookie is included in the request.
•When the server receives the request, it knows that this is
an old client, not a new one.
•Note that the contents of the cookie are never read by the
browser or disclosed to the user.
• It is a cookie made by the server and eaten by the server.
Web Caching
• 1. The client sends the MAIL FROM message to introduce the sender
of the message. It includes the mail address of the sender (mailbox
and the domain name). This step is needed to give the server the
return mail address for returning errors and reporting messages.
• 2. The server responds with code 250 or some other appropriate
code.
• 3. The client sends the RCPT TO (recipient) message, which
includes the mail address of the recipient.
• 4. The server responds with code 250 or some other appropriate
code.
• 5. The client sends the DATA message to initialize the message
transfer.
• 6. The server responds with code 354 (start mail input)
or some other appropriate message.
• 7. The client sends the contents of the message in consecutive
lines. The message is terminated by a line containing just one
period.
• 8. The server responds with code 250 (OK) or some other
appropriate code.
Connection Termination
• After the message is transferred successfully, the client terminates
the connection.
• This phase involves two steps.
• 1. The client sends the QUIT command.
• 2. The server responds with code 221 or some other appropriate
code.
• SMTP is a push protocol; it pushes the message from the client
to the server.
• The receiver needs a pull protocol; the client must pull
messages from the server.
• Two message access protocols are available: Post Office Protocol
version 3 (POP3) and Internet Mail Access Protocol version 4
(IMAP4).
• Difference between HTTP and SMTP
POP3
• Post Office Protocol, version 3 (POP3) is simple but limited in
functionality.
• 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 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.
• The delete mode is normally used when the user is working at
her permanent computer and can save and organize the
received mail after reading or replying.
• The keep mode is normally used when the user accesses her mail
away from her primary computer (for example, from a laptop).
The mail is read but kept in the system for later retrieval and
organizing
POP3 Drawbacks