1 internet services. 2 telnet protocol 3 telnet allows a person sitting on one computer to work on...

93
1 Internet Services

Upload: blaise-conley

Post on 27-Dec-2015

221 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

1

Internet Services

Page 2: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

2

TELNET Protocol

Page 3: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

3

TELNET

• Allows a person sitting on one computer to work on another computer.

• Starts a remote session on another machine.• Requires a person to supply login name and

password to gain entry.• Command:

telnet <domain_name>

telnet <ip_address> A B

Page 4: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

4

TELNET (contd.)

• Why required?– For using software only available on the remote

host.– For using devices (like printer) connected to the

remote host.

• Typical scenario– Many users do a telnet to a remote server, and

work there.– Server is a bigger and faster computer.

Page 5: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

5

TELNET (contd.)

• By default connection is established over port 23.

• Any other port number can also be specified. telnet cse.iitkgp.ernet.in 25

Page 6: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

6

A Sample TELNET Session

SUNNY>> telnet cseTrying 144.16.192.57...Connected to cse.Escape character is '^]'. Linux 1.2.8 (cse) (ttyp0)  cse login: isgPassword: Last login: Wed Jun 11 12:17:55 from 144.16.202.210Linux 1.2.8. (POSIX).You have new mail. cse:~$

Page 7: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

7

FTP Protocol

Page 8: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

8

File Transfer Protocol (FTP)

• Allows a person to transfer files between two machines.

• Requires a person to supply login name and password to gain entry.

• Command: ftp <domain_name>

ftp <ip_address>

Page 9: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

9

Anonymous FTP

• A special form of FTP which has become very popular.– Does not require a person to know login name

and password.– In place of login name, type the word

anonymous.– In place of password, type the email address.

• Huge amount of resources are available in anonymous FTP sites.

Page 10: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

10

FTP Process Model

Control

DataTransfer

Control

INTERNET

Port 21

DataTransfer

SERVERCLIENT

Port 22

Page 11: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

11

How FTP Works?

• Two connections established:– A control connection over port 21, that

remains all through a session.– A temporary port number, used for every file

being transferred.• New connection established for every file

transfer.

Page 12: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

12

Typical FTP Commands

• put, mput– Send one (or more) file(s).

• get, mget– Receive one (or more) file(s).

• hash– Indicates progress of file transfer.

• prompt– Prompts user before actual transfer of each file.

• bin, asc– Selects binary or ascii mode of transfer.

• exit– Terminates connection with ftp server.

Page 13: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

13

Sample FTP Sessions

SUNNY>> ftp cseindigoConnected to cseindigo.220 cseindigo FTP server ready.Name (cseindigo:isg): isg331 Password required for isg.Password:230 User isg logged in.Remote system type is UNIX.Using binary mode to transfer files.ftp>

Page 14: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

14

Sample FTP Sessions (contd.)

ftp> dir200 PORT command successful.150 Opening ASCII mode data connection for '/bin/ls'.total 97drwxr-xr-x 2 isg faculty 512 Oct 8 1995 PROJECTS-rw-r--r-- 1 isg faculty 7693 Mar 31 1995 lan-cse.fig-rw-r--r-- 1 isg faculty 6578 Apr 26 1995 lan-cse.fig-rw-r--r-- 1 isg faculty 6721 Jul 12 1995 newlan.fig226 Transfer complete.

Page 15: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

15

Sample FTP Sessions (contd.)

ftp> get lan-cse.fig200 PORT command successful.150 Opening BINARY mode data connection for 'lan-cse.fig' (6721 bytes).226 Transfer complete.6721 bytes received in 0.0389 secs (1.7e+02 Kbytes/sec) ftp> quit221 Goodbye. SUNNY>>

Page 16: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

16

Electronic Mail

Indian Institute of Technology Kharagpur

Page 17: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

17

Electronic Mail

• Most widely used application on the Internet.

• For sending mails:– Simple Mail Transfer Protocol (SMTP)– Multi-purpose Internet Mail Extension (MIME)

• For receiving mails:– Post office protocol version 3 (POP3)– Internet mail access protocol (IMAP)

Page 18: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

18

Simple Mail Transfer Protocol

• Based on RFC 821.• Transmits simple text messages only.

– 7-bit ASCII format.

• Uses information written on envelope of mail.– Message header.– Contains recipient address and other information.

• Does not look at contents.– Message body.

Page 19: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

19

Message Header

Message Body

MailMessage

Page 20: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

20

Basic Operation

• Mail is created by user agent program (mail client).– mailx, pine, Outlook, etc.

• Messages queued and sent as input to SMTP sender program.– Typically a server process.– Daemon on UNIX.

• sendmail or qmail• Listens on port number 25

Page 21: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

21

SMTP Mail Flow

UserAgent

SMTPServer

Header

MailBody

Header

MailBody

Header

MailBody

Header

MailBody

Header

MailBody

Header

MailBody

User Mailboxes

SMTPServer

SMTPServer

Port 25

Port 25

Port 25

Page 22: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

22

Mail Message Contents

• Each queued message has:– Message text

• RFC 822 header with message envelope and list of recipients.

• Message body, composed by user.– A list of mail destinations

• Derived by user agent / SMTP server from header.

• May require expansion of mailing lists.

Page 23: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

23

SMTP Sender

• Takes message from queue.• Transmits to proper destination host.

– Via SMTP transaction.– Over one or more TCP connections to port 25.

• When all destinations have been processed, message is deleted.

Page 24: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

24

Optimization

• If message is sent to multiple users on a given host, it is sent only once.– Delivery to users handled at destination host.

• If multiple messages are ready for given host, a single TCP connection can be used.– Saves overhead of setting up and dropping

connection.

Page 25: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

25

Possible Errors

• Host unreachable• Host out of operation• TCP connection fail during transfer• Faulty destination address

– User error– Target user address has changed– Redirect if possible– Inform user if not

Page 26: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

26

SMTP Protocol - Reliability

• Used to transfer messages from sender to receiver over TCP connection.– Uses port number 25.

• Attempts to provide reliable service.• No guarantee to recover lost messages.• No end-to-end ACK to sender.• Error indication report not guaranteed.

Page 27: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

27

SMTP Receiver

• Accepts arriving message.• Places in user mailbox or copies to

outgoing queue for forwarding.• Receiver must:

– Verify local mail destinations.– Deal with errors

• Transmission• Lack of disk space

Page 28: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

28

SMTP Forwarding

• Mostly direct transfer from sender host to receiver host.

• May go through intermediate mail servers via forwarding capability.– Sender can specify route.

Page 29: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

29

SMTP Mail Flow

UserAgent

SMTPServer

Header

MailBody

Header

MailBody

Header

MailBody

Header

MailBody

Header

MailBody

Header

MailBody

User Mailboxes

SMTPServer

SMTPServer

Port 25

Port 25

Port 25

Page 30: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

30

SMTP System Overview

• Commands and responses exchanged between sender and receiver.

• Initiative with sender.– Establishes TCP connection.

• Sender sends commands to receiver.– e.g. HELO <domain><CRLF>

• Each command generates exactly one reply.– e.g. 250 requested mail action ok; completed.

Page 31: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

31

SMTP Replies

• Starts with 3-digit code.• Leading digit indicates category.

– 2xx -- Positive completion reply– 3xx -- Positive intermediate reply– 4xx -- Transient negative completion reply – 5xx -- Permanent negative completion reply

Page 32: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

32

Operation Phases

a) Connection setup

b) Exchange of command-response pairs

c) Connection termination

Page 33: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

33

a) Connection Setup

• Sender opens TCP connection with receiver.• Once connected, receiver identifies itself.

220 <domain> service ready• Sender identifies itself.

HELO• Receiver accepts sender’s identification.

250 OK• If mail service not available, the response to the

second step above becomes: 421 service not available

Page 34: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

34

b) Mail Transfer Commands

• The MAIL FROM command identifies originator.– Gives reverse path to be used for error

reporting.– Receiver returns 250 OK or appropriate failure /

error message.

Page 35: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

35

• One or more RCPT TO commands identify recipients for the message.– Separate reply for each recipient.

• The DATA command transfers message text.– End of message indicated by a line containing

just period (.)

Page 36: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

36

c) Closing Connection

• Two steps:– Sender sends QUIT and waits for reply.– Then initiate TCP close operation.

• Receiver initiates TCP close after sending reply to QUIT.

Page 37: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

37

An Example SMTP Session

• How to connect to an SMTP server? telnet servername 25

– A TCP connection gets established over port number 25.

– The telnet client and the mail server can now start a dialogue.

Page 38: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

38

An Example SMTP Session

S: 220 hotmail.com Simple Mail Transfer Service ReadyC: HELO yahoo.comS: 250 hotmail.com

C: MAIL FROM: <[email protected]> S: 250 OK

C: RCPT TO: <[email protected]> S: 250 OK

C: RCPT TO: <[email protected]> S: 250 OK

Page 39: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

39

An Example SMTP Session

C: DATA

S: 354 Start mail input; end with (.)

C: … actual contents of the message …

C: ………

C: ………

C: .S: 250 OK

C: QUIT

S: 221 hotmail.com Service closing transmission channel

Page 40: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

40

Mail Access Protocols

• Two mail access protocols are widely used:1. Post Office Protocol, version 3 (POP3)

2. Internet Mail Access Protocol version 4 (IMAP4).

Page 41: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

41

What do they do?

User Mailboxes

on SMTP server

Mail Client

POP3 / IMAP

Page 42: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

42

POP3

• The client POP3 software is installed on the recipient machine, and the server POP3 software installed on mail server.– The client (user agent) opens a connection

with the server on TCP port number 110.– Sends user name and password.– Can access the mails, one by one.

Page 43: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

43

POP3 (contd.)

– Two modes:• Delete mode – mails deleted as they are read• Keep mode – mails remain in the mailbox

– POP3 has commands for:• Log in• Log out• Fetch messages• Delete messages

Page 44: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

44

IMAP4

• Provides the following extra features:– A user can check the email header before

downloading.– A user can search the contents of the email for

a specific string prior to downloading.– A user can create, delete, or rename mailboxes

on the mail server.– A user can create a hierarchy of mailboxes in a

folder for email storage.

Page 45: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

45

Multipurpose Internet Mail Extension (MIME)

• SMTP cannot transmit non-text messages.– Solutions (like uuencode) exists on some

systems, but are not standardized.

• Cannot transmit text that includes international characters (e.g. â, å, ä, è, é, ê, ë).– Need 8 bit ASCII.

Page 46: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

46

• Servers may reject mail over certain size.• Some SMTP implementations do not

adhere to standard.– CRLF, truncate or wrap long lines, removal of

white space, etc.

Page 47: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

47

Overview of MIME

• Five new message header fields:– MIME-version– Content-type– Content-transfer-encoding– Content-Id– Content-description

• A number of content types and transfer encoding formats have been defined.

Page 48: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

48

Content Types

• Text body• Multipart

– Mixed, Parallel, Alternative

• Message– RFC 822, Partial,

External-body• Image

– jpeg, gif

• Video– mpeg

• Audio– Basic

• Application– Postscript– octet stream

Page 49: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

49

MIME Transfer Encodings

• Specifies how the mail body is wrapped for transmission.

• Content transfer encoding field can have six possible values.– 7bit, 8bit, binary:

• No encoding done for these three.

• Provide information about nature of data.

Page 50: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

50

– Quoted-printable• Data mostly printable ASCII characters.• Non-printing characters represented by hex code.

– Base64• Maps arbitrary binary input onto printable output.

– X-token• Named nonstandard encoding.

Page 51: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

51

Base64 Encoding

6 bits 6 bits 6 bits6 bits

8 bits8 bits 8 bits 8 bits

R64 R64 R64 R64

• Expands the message by 33%.

• Uses the symbols A..Z, a..z, 0..9, +, /

Page 52: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

52

MIME Header ExampleFrom: Indranil Sengupta <[email protected]>To: Jaswinder Ahuja <[email protected]>Subject: Simple MessageMIME-Version: 1.0Content-type: multipart/mixed; boundary="simple boundary"

This is the preamble. It is to be ignored, though it is a handy place for mail composers to include an explanatory note.--simple boundary

This is implicitly typed plain text. It does NOT end with a linebreak.-- simple boundaryContent-type: text/plain; charset=us-ascii

This is explicitly typed plain ASCII text. It DOES end with a linebreak.

--simple boundary--This is the epilogue. It is also to be ignored.

Page 53: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

53

Another MIME ExampleFrom: Indranil Sengupta <[email protected]>To: Jaswinder Ahuja <[email protected]>Subject: Formatted text mailMIME-Version: 1.0Content-type: multipart/alternative; boundary=boun42

--boun42

Content-type: text/plain; charset=us-ascii

... plain text version of message goes here ...

--boun42Content-type: text/enriched

... RFC1896 text/enriched version of the same message goes here

...--boun42--

Page 54: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

54

World Wide Web

Indian Institute of Technology Kharagpur

Page 55: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

55

World Wide Web (WWW)

• Latest revolution in the internet scenario.• Allows multimedia documents to be

shared between machines.– Containing text, image, audio, video,

animation.

• Basically a huge collection of inter-linked documents.– Billions of documents.– Inter-linked in any possible way.– Resembles a cob-web.

Page 56: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

56

WWW (contd.)

• Where do the documents reside?– On web servers.– Also called Hyper Text Transfer Protocol

(HTTP) servers.

• They are typically written in– Hyper Text Markup Language (HTML).

• Documents get formatted/displayed using– Web browsers

• Internet Explorer• Netscape• Mosaic• Konquerer

Page 57: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

57

What is HTTP?

• Hyper Text Transfer Protocol– A protocol using which web clients (browsers)

interact with web servers.

• It is a stateless protocol.– Fresh connection for every item to be

downloaded.

• Transfers hypertext across the Internet.– A text with links to other text documents.– Resembles a cob-web, and hence the name

World Wide Web (WWW).

Page 58: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

58

HTTP Protocol

• Web clients (browsers) and web servers communicate via HTTP protocol.

• Basic steps:– Client opens socket connection to the HTTP

server.• Typically over port 80.

– Client sends HTTP requests to server.– Server sends back response.– Server closes connection.

• HTTP is a stateless protocol.

Page 59: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

59

Illustration

Web Servers

WebClient

http request

http response

http request

http response

Page 60: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

60

HTTP Request Format

• A client request to a server consists of:– Request method– Path portion of the HTTP URL– Version number of the HTTP protocol– Optional request header information– Blank line– POST or PUT data if present.

Page 61: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

61

HTTP Request Methods

• GET– Most common HTTP method.– Returns the contents of the specified

document.– Places any parameters in request header.– Can also be used to submit forms:

• The form data is URL-encoded and appended to the GET command URL.

Page 62: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

62

Illustration of GET

– A very simple HTTP connection to a server. telnet www.facweb.iitkgp.ac.in http

– Client sends request for a file: GET /test.html HTTP/1.0

– The server sends back the response: HTTP/1.1 200 OK Date: Sun, 22 May 2005 09:51:42 GMT Server: Apache/1.3.33 (Win32) Last-Modified: Sun, 22 May 2005 09:51:10 GMT Accept-Ranges: bytes Content-Length: 119 Connection: close

Page 63: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

63

Illustration of GET (contd.)

Content-Type: text/html

<html> <head> <title> A test page </title> </head>

<body>

This is the body of the test page.

</body>

</html>

Page 64: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

64

HTTP Request Methods (contd.)

• HEAD– Returns only the header information of the

specified document.– Used by clients to determine the file size,

modification date, server version, etc.

Page 65: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

65

Illustration of HEAD

• Client sendsHEAD /index.html HTTP/1.0

• Server responds back with:HTTP/1.1 200 OK

Date: Sun, 22 May 2005 10:08:37 GMT

Server: Apache/1.3.33 (Win32)

Last-Modified: Thu, 03 May 2001 11:30:38 GMT

Accept-Ranges: bytes

Content-Length: 1494

Connection: close

Content-Type: text/html

Page 66: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

66

HTTP Request Methods (contd.)

• POST– Used to send data to the server to be processed in

some way, as in a CGI script.– Basic difference from GET:

• A block of data is sent along with the request. Extra headers like Content-Type and Content-Length are used for this purpose.

Page 67: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

67

• The requested object is not a resource to retrieve. Rather, it is a script that can handle the data being sent.

• The server response is not a static file; but is generated dynamically as the program output.

Page 68: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

68

Illustration of POST

– A typical form submission, using POST is illustrated below:

POST /cgi-bin/myscript.cgi HTTP/1.0

From: [email protected]

User-Agent: HTTPTool/1.0

Content-Type: application/x-www-form-urlencoded

Content-Length: 32

Roll=1234&Sex=M&Age=20

Page 69: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

69

HTTP Request Methods (contd.)

• PUT– Replaces the contents of the specified

document with data supplied along with the command.

– Not used widely.

• DELETE:– Deletes the specified document from the

server.– Not used widely.

Page 70: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

70

HTTP Request Headers

• After a HTTP request line, a client can send any number of header fields.– Usually optional – used to convey some

information.– Some commonly used fields:

• Accept: MIME types client accepts, in order of preference.

• Connection: connection options, close or Keep-Alive.

Page 71: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

71

• Content-Length: number of bytes of data to follow.

• Content-Type: MIME type and subtype of the data that follows.

• Pragma: “no-cache” option directs the server/proxy to return a fresh document even though a cached copy may exist.

Page 72: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

72

HTTP Request Data

• To be given if the request type is either PUT or POST.– Send the data immediately after the HTTP

request header, and a blank line.

Page 73: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

73

HTTP Response

• An initial response line.– Also called the status line.– Consists of three parts separated by spaces

• The HTTP version• A 3-digit response status code• An English phrase describing the status code.

HTTP/1.0 200 OK

HTTP/1.0 404 Not Found

Page 74: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

74

HTTP Response (contd.)• Header information, followed by a blank

line, and then the data.

HTTP/1.1 200 OKDate: Sun, 22 May 2005 09:51:42 GMTServer: Apache/1.3.33 (Win32)Last-Modified: Sun, 22 May 2005 09:51:10 GMTContent-Length: 119Connection: closeContent-Type: text/html

<html> <head> <title> A test page </title> </head><body> This is the body of the test page.</body> </html>

Page 75: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

75

3-digit Status Code

• 1xx– Indicates informational messages only.

• 2xx– Indicates successful transaction.

• 3xx– Redirects the client to another URL.

• 4xx– Indicates client error, such as unauthorized

request.

• 5xx– Indicates internal server error.

Page 76: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

76

Common Status Codes

• 200 OK• 301 Moved Permanently• 302 Moved Temporarily• 401 Unauthorized• 403 Forbidden• 404 Not Found• 500 Internal Server Error

Page 77: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

77

HTTP Response Headers

• Common response headers include:– Content-Length

• Size of the data in bytes.

– Content-Type• MIME type and subtype of data being sent.

– Date• Current date.

– Expires• Date at which document expires.

– Last-Modified– Set-Cookie

• Name/value pair to be stored as cookie.

Page 78: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

78

HTTP Response Data

• A blank line follows the response header, and the data follows next.– No upper limit on data size.

• HTTP/1.0– Server typically closes connection after

completing a transaction.

• HTTP/1.1– Server keeps the connection open by default,

across transactions.

Page 79: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

79

HTTP version 1.1

• Current standard and widely used.– Became IETF draft standard in 2001.

• Improvements over HTTP 1.0:– Requires host identification.

• Allows multi-homed servers.• More than one domain living on same server.

GET /index.html HTTP/1.1Host: www.facweb.iitkgp.ac.in<blank line>

Page 80: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

80

HTTP version 1.1 (contd.)

– Default support for persistent connections.• Multiple transactions over a single connection.

– Support for content negotiation.• Decides on the best among the available representations.• Server-driven or browser-driven.

– Browsers can request part of document.• Specify the bytes using Range header.• Browser can ask for more than one range.• Continue interrupted downloads.

Range: bytes=1200-3500

Page 81: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

81

HTTP version 1.1 (contd.)

– Efficient caching support• A document caching model that allows both

the server and the client to control the level of cachability and update conditions and requirements.

• HTTP 1.1 requires several extra things from both clients and servers.– Mandatory to know these if one is trying to

write a HTTP client or server.

Page 82: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

82

HTTP 1.1 Client Requirements

• The clients must do the following:– Include the Host: header with each request.– Either support persistent connections, or include

the Connection: close header with each request.

– Handle the 100 Continue response.– Accept responses with chunked data.

Page 83: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

83

HTTP 1.1 Server Requirements

• The servers must do the following:– Require the Host: header from HTTP 1.1 clients.– Accepts absolute URL’s in a request.– Accept requests with chunked data.– Include the Date: header in each response.– Support at least the GET and HEAD methods.– Support HTTP 1.0 requests.– Either support persistent connections, or include

the Connection: close header with each request.

Page 84: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

84

How a Web Server Works?

Page 85: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

85

Requirements of a Web Server

• Simple requirements:– Able to accept HTTP requests, and respond to

them.– Support for GET and HEAD, possibly also

POST.– Able to handle server-side scripts.

• Executables residing on the server.• They get executed when specified.• Their output sent back to the client;

typically as a HTML page.

Page 86: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

86

Directory Structure

• When a web server is installed:– A http root directory gets created.

• For example, “/home/httpd”– There is a directory under the http root that

acts as the http home directory.• For example, “/home/httpd/docs”

– There is a directory under the http root under which all the CGI and other scripts are to be stored.

• For example, “/home/cgi-bin”• Server-side exec permission provided

Page 87: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

87

Directory Structure (contd.)

HTTP Root

cgi-binHTTP Home Other

WebFolders

Page 88: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

88

Default Web Page

• There is a default web page that gets returned by the server if no explicit document path is specified.– index.htm or index.html.– Any other name can also be specified through

server script configuration.

• Can be accessed as:GET www.xyz.com HTTP/1.0

Page 89: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

89

How are Scripts Handled?

• Server-side scripts– A file that is to be executed by the server, and

the output sent back to the client.

• How does the server know?– Two ways:

• GET command with a “?”.• POST command.

Page 90: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

90

GET Command with a “?”

• Consider an example HTTP command:GET /cgi-bin/xyz.pl ? roll=1234 & sex=M

• What happens?– Server identifies the “?” following the GET.– Identifies xyz.pl as a program to be executed.– Allows the xyz.com program to read the values

present in the string following the “?”.• How, to be discussed later

– The output generated by the xyz.com program is sent back to the client.

Page 91: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

91

POST Command

• Works similar to get.• Differences:

– The name-value pairs are present as data following the header lines and a blank line.

– Not limited by the maximum size of a string (as in GET).

– The executable program can read the data values.

• How, to be discussed later.

Page 92: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

92

POST Command :: Example

POST /cgi-bin/myscript.cgi HTTP/1.0

From: [email protected]

User-Agent: HTTPTool/1.0

Content-Type: application/x-www-form-urlencoded

Content-Length: 32

Roll = 1234 & Sex = M & Age = 20

Page 93: 1 Internet Services. 2 TELNET Protocol 3 TELNET Allows a person sitting on one computer to work on another computer. Starts a remote session on another

93

Points to Note

• The executable program that runs on the server can be written in any language.– Shell script (C shell, bourne shell, etc.)– Perl– ASP– PHP– C, Java (requires servlet support)

• Necessary support for executing must be there in the server.

• For example, ASP can run under IIS but not under Apache.