33
1-1 HTTP and Electronic Mail Services Objectives: TCP, UDP, HTTP protocols HTTP clients and servers Electronic mail

1-1 HTTP and Electronic Mail Services Objectives: TCP, UDP, HTTP protocols HTTP clients and servers Electronic mail

Embed Size (px)

Citation preview

Page 1: 1-1 HTTP and Electronic Mail Services Objectives:  TCP, UDP, HTTP protocols  HTTP clients and servers  Electronic mail

1-1

HTTP and Electronic Mail Services

Objectives: TCP, UDP, HTTP protocols HTTP clients and servers Electronic mail

Page 2: 1-1 HTTP and Electronic Mail Services Objectives:  TCP, UDP, HTTP protocols  HTTP clients and servers  Electronic mail

1-2

TCP/IP As A Protocol Suite

Application Telnet, FTP, Web, e-mail, etc.

Transport TCP, UDP

Network IP, ICMP, IGMP

Data Link +Physical device driver and interface card

Page 3: 1-1 HTTP and Electronic Mail Services Objectives:  TCP, UDP, HTTP protocols  HTTP clients and servers  Electronic mail

1-3

TCP Connection Management

Recall: TCP sender, receiver establish “connection” before exchanging data segments

initialize TCP variables: seq. #s buffers, flow control info

(e.g. RcvWindow) client: connection initiator Socket clientSocket = new

Socket("hostname","port

number"); server: contacted by client Socket connectionSocket =

welcomeSocket.accept();

Three way handshake:

Step 1: client host sends TCP SYN segment to server specifies initial seq # no data

Step 2: server host receives SYN, replies with SYNACK segment

server allocates buffers specifies server initial

seq. #Step 3: client receives SYNACK,

replies with ACK segment, which may contain data

Page 4: 1-1 HTTP and Electronic Mail Services Objectives:  TCP, UDP, HTTP protocols  HTTP clients and servers  Electronic mail

1-4

TCP Connection Establishment

client

SYN, seq=x

server

SYN+ACK, seq=y, ack=x+1

ACK, ack=y+1

CLOSED

LISTEN

SYN_SENTSYN_RCVD

Established

Passive open

SYN/SYN+ACK

ACK

Active open;SYN

SYN+ACK/ACK

Solid line for client

Dashed line for server

Page 5: 1-1 HTTP and Electronic Mail Services Objectives:  TCP, UDP, HTTP protocols  HTTP clients and servers  Electronic mail

1-5

TCP Connection Termination

client

FIN

server

ACK

ACK

FIN

closing

tim

ed w

ait

FIN_WAIT1

FIN_WAIT2

CLOSE_WAIT

LAST_ACK

CLOSED

TIME_WAIT

CLOSED

Page 6: 1-1 HTTP and Electronic Mail Services Objectives:  TCP, UDP, HTTP protocols  HTTP clients and servers  Electronic mail

1-6

Multiplexing/Demultiplexing

Use same communication channel between hosts for several logical communication processes

How does Mux/DeMux work? Sockets: doors between process & host UDP socket: (dest. IP, dest. Port) TCP socket: (src. IP, src. port, dest. IP, dest. Port)

TransportLayer

NetworkLayer

TransportLayer

NetworkLayer

HTTP

FTP

Telnet

Page 7: 1-1 HTTP and Electronic Mail Services Objectives:  TCP, UDP, HTTP protocols  HTTP clients and servers  Electronic mail

1-7

Connectionless demux

UDP socket identified by two-tuple: (dest IP address, dest port number)

When host receives UDP segment: checks destination port number in segment directs UDP segment to socket with that port number

IP datagrams with different source IP addresses and/or source port numbers are directed to the same socket

Page 8: 1-1 HTTP and Electronic Mail Services Objectives:  TCP, UDP, HTTP protocols  HTTP clients and servers  Electronic mail

1-8

Connection-oriented demux

TCP socket identified by 4-tuple: source IP address source port number dest IP address dest port number

recv host uses all four values to direct segment to appropriate socket

Server host may support many simultaneous TCP sockets: each socket identified

by its own 4-tuple

Web servers have different sockets for each connecting client non-persistent HTTP will

have different socket for each request

Page 9: 1-1 HTTP and Electronic Mail Services Objectives:  TCP, UDP, HTTP protocols  HTTP clients and servers  Electronic mail

1-9

Example Standardized Services

DNSFTP (your Assignment #1)

SCPPing

FingerTelnet, SSH

SMTPPOP IMAP

HTTP (your assignment #3)

Page 10: 1-1 HTTP and Electronic Mail Services Objectives:  TCP, UDP, HTTP protocols  HTTP clients and servers  Electronic mail

1-10

Web and HTTP

First some jargon Web page consists of objects Object can be HTML file, JPEG image, Java applet, audio

file,… Web page consists of base HTML-file which includes

several referenced objects Each object is addressable by a URL Example URL:

www.someschool.edu/someDept/pic.gif

host name path name

Page 11: 1-1 HTTP and Electronic Mail Services Objectives:  TCP, UDP, HTTP protocols  HTTP clients and servers  Electronic mail

1-11

HTTP overview

HTTP: hypertext transfer protocol

Web’s application layer protocol client/server model

client: browser that requests, receives, “displays” Web objects

server: Web server sends objects in response to requests

HTTP 1.0: RFC 1945 HTTP 1.1: RFC 2068

PC runningExplorer

Server running

Apache Webserver

Mac runningNavigator

HTTP request

HTTP request

HTTP response

HTTP response

Page 12: 1-1 HTTP and Electronic Mail Services Objectives:  TCP, UDP, HTTP protocols  HTTP clients and servers  Electronic mail

1-12

Steps For Fetching URLs

The browser makes up an absolute URL if URL is relative The browser examines the protocol part and the host

part Browser uses DNS to resolve host name to IP address For HTTP protocol, the browser makes a TCP connection

to IP address and port 80 The port maybe :portno following the hostname in URL

The browser sends a GET request as in: GET /path/somefile.htm HTTP/1.0

The server sends the file and closes the connection. Browser renders file. If it is HTML file then any image

referenced by some <img> tag, then go back to step 4

Page 13: 1-1 HTTP and Electronic Mail Services Objectives:  TCP, UDP, HTTP protocols  HTTP clients and servers  Electronic mail

1-13

HTTP overview (continued)

Uses TCP: client initiates TCP

connection (creates socket) to server, port 80

server accepts TCP connection from client

HTTP messages (application-layer protocol messages) exchanged between browser (HTTP client) and Web server (HTTP server)

TCP connection closed

HTTP is “stateless” server maintains no

information about past client requests

Protocols that maintain “state” are complex!

past history (state) must be maintained

if server/client crashes, their views of “state” may be inconsistent, must be reconciled

Page 14: 1-1 HTTP and Electronic Mail Services Objectives:  TCP, UDP, HTTP protocols  HTTP clients and servers  Electronic mail

1-14

HTTP connections

Nonpersistent HTTP At most one object is

sent over a TCP connection.

HTTP/1.0 uses nonpersistent HTTP

Persistent HTTP Multiple objects can

be sent over single TCP connection between client and server.

HTTP/1.1 uses persistent connections in default mode

Page 15: 1-1 HTTP and Electronic Mail Services Objectives:  TCP, UDP, HTTP protocols  HTTP clients and servers  Electronic mail

1-15

Nonpersistent HTTPSuppose user enters URL www.someSchool.edu/someDepartment/home.index

1a. HTTP client initiates TCP connection to HTTP server (process) at www.someSchool.edu on port 80

2. HTTP client sends HTTP request message (containing URL) into TCP connection socket. Message indicates that client wants object someDepartment/home.index

1b. HTTP server at host www.someSchool.edu waiting for TCP connection at port 80, “accepts” connection and notifies the client

3. HTTP server receives request message, forms response message containing requested object, and sends message into its socket

time

(contains text, references to 10

jpeg images)

Page 16: 1-1 HTTP and Electronic Mail Services Objectives:  TCP, UDP, HTTP protocols  HTTP clients and servers  Electronic mail

1-16

Nonpersistent HTTP (cont.)

5. HTTP client receives response message containing html file, displays html. Parsing html file, finds 10 referenced jpeg objects

6. Steps 1-5 repeated for each of 10 jpeg objects

4. HTTP server closes TCP connection.

time

Page 17: 1-1 HTTP and Electronic Mail Services Objectives:  TCP, UDP, HTTP protocols  HTTP clients and servers  Electronic mail

1-17

Response time modeling

Definition of RTT: time to send a small packet to travel from client to server and back.

Response time: one RTT to initiate TCP

connection one RTT for HTTP request and

first few bytes of HTTP response to return

file transmission timetotal = 2RTT+transmit time

time to transmit file

initiate TCPconnection

RTT

requestfile

RTT

filereceived

time time

Page 18: 1-1 HTTP and Electronic Mail Services Objectives:  TCP, UDP, HTTP protocols  HTTP clients and servers  Electronic mail

1-18

Persistent HTTP

Nonpersistent HTTP issues: requires 2 RTTs per object OS must work and allocate

host resources for each TCP connection

but browsers often open parallel TCP connections to fetch referenced objects

Persistent HTTP server leaves connection

open after sending response

subsequent HTTP messages between same client/server are sent over the same connection

Persistent without pipelining: client issues new request

only when previous response has been received

one RTT for each referenced object

Persistent with pipelining: default in HTTP/1.1 client sends requests as

soon as it encounters a referenced object

as little as one RTT for all the referenced objects

Page 19: 1-1 HTTP and Electronic Mail Services Objectives:  TCP, UDP, HTTP protocols  HTTP clients and servers  Electronic mail

1-19

HTTP request message

Two types of HTTP messages: request, response HTTP request message:

ASCII (human-readable format)

GET /somedir/page.html HTTP/1.1Host: www.someschool.edu User-agent: Mozilla/4.0Connection: close Accept-language:fr

(extra carriage return, line feed)

request line(GET, POST,

HEAD commands)

header lines

Carriage return, line feed

indicates end of message

Page 20: 1-1 HTTP and Electronic Mail Services Objectives:  TCP, UDP, HTTP protocols  HTTP clients and servers  Electronic mail

1-20

User-server state: cookies

Many major Web sites use cookies

Four components:1) cookie header line in

the HTTP response message

2) cookie header line in HTTP request message

3) cookie file kept on user’s host and managed by user’s browser

4) back-end database at Web site

Page 21: 1-1 HTTP and Electronic Mail Services Objectives:  TCP, UDP, HTTP protocols  HTTP clients and servers  Electronic mail

1-21

Cookies: keeping “state” (cont.)

client server

usual http request msgusual http response

+Set-cookie: 1678

usual http request msg

cookie: 1678usual http response

msg

usual http request msg

cookie: 1678usual http response msg

cookie-specificaction

cookie-spectificaction

servercreates ID

1678 for user

entry in backend

database

access

acce

ss

Cookie file

amazon: 1678ebay: 8734

Cookie file

ebay: 8734

Cookie file

amazon: 1678ebay: 8734

one week later:

Page 22: 1-1 HTTP and Electronic Mail Services Objectives:  TCP, UDP, HTTP protocols  HTTP clients and servers  Electronic mail

1-22

Cookies (continued)

What cookies can bring:

authorization shopping carts recommendations one-click shopping user session state

(Web e-mail)

Cookies and privacy: cookies permit sites to

learn a lot about you you may supply name

and e-mail to sites search engines use

redirection & cookies to learn yet more

advertising companies obtain info across sites

aside

Page 23: 1-1 HTTP and Electronic Mail Services Objectives:  TCP, UDP, HTTP protocols  HTTP clients and servers  Electronic mail

1-23

Conditional GET

Goal: don’t send object if cache has up-to-date cached version

cache: specify date of cached copy in HTTP requestIf-modified-since:

<date> server: response contains

no object if cached copy is up-to-date: HTTP/1.0 304 Not

Modified

cache server

HTTP request msgIf-modified-since:

<date>

HTTP responseHTTP/1.0

304 Not Modified

object not

modified

HTTP request msgIf-modified-since:

<date>

HTTP responseHTTP/1.0 200 OK

<data>

object modified

Page 24: 1-1 HTTP and Electronic Mail Services Objectives:  TCP, UDP, HTTP protocols  HTTP clients and servers  Electronic mail

1-24

Electronic Mail

Three major components: user agents mail servers simple mail transfer protocol:

SMTP

User Agent a.k.a. “mail reader” composing, editing, reading mail

messages e.g., Eudora, Outlook, elm,

Netscape Messenger, Thunderbird

outgoing, incoming messages stored on server

user mailbox

outgoing message queue

mailserver

useragent

useragent

useragent

mailserver

useragent

useragent

mailserver

useragent

SMTP

SMTP

SMTP

Page 25: 1-1 HTTP and Electronic Mail Services Objectives:  TCP, UDP, HTTP protocols  HTTP clients and servers  Electronic mail

1-25

Email using SMTP/IMAP/POP Email consists of two components

Simple Mail Transfer Protocol (SMTP) for email clients to send out emails (e.g. smtp.nd.edu, port 25)

Internet Message Access Protocol (IMAP) or Post Office Protocol (POP)

• email clients to receive your emails (e.g. imap.nd.edu, port 143)

You can use telnet to “talk” to these servers directly

E.g. type ‘telnet smtp.nd.edu 25’ and then type ‘help’

Page 26: 1-1 HTTP and Electronic Mail Services Objectives:  TCP, UDP, HTTP protocols  HTTP clients and servers  Electronic mail

1-26

Email using SMTP/IMAP/POP For SMTP, your client (say Outlook), connects

to smtp.nd.edu and then delivers an email destined for [email protected]

Smtp.nd.edu then locates the SMTP server responsible for AOL. These servers may delegate to other SMTP servers. Eventually it reaches [email protected]

Friend will use IMAP or POP to retrieve this email

Page 27: 1-1 HTTP and Electronic Mail Services Objectives:  TCP, UDP, HTTP protocols  HTTP clients and servers  Electronic mail

1-27

Electronic Mail: SMTP [RFC 2821]

uses TCP to reliably transfer email message from client to server, port 25

direct transfer: sending server to receiving server no middle server in-between!

three phases of transfer handshaking (greeting) transfer of messages closure

command/response interaction commands: ASCII text response: status code and phrase

messages must be in 7-bit ASCII (mostly)

Page 28: 1-1 HTTP and Electronic Mail Services Objectives:  TCP, UDP, HTTP protocols  HTTP clients and servers  Electronic mail

1-28

Mail message format

SMTP: protocol for exchanging email messages

RFC 2822: standard for text message format:

header lines, e.g., To: From: Subject:different from SMTP

commands! body

the “message”, ASCII characters only (mostly)

header

body

blankline

Page 29: 1-1 HTTP and Electronic Mail Services Objectives:  TCP, UDP, HTTP protocols  HTTP clients and servers  Electronic mail

1-29

Message format: multimedia extensions

MIME: multimedia mail extension, RFC 2045, 2056 additional lines in msg header declare MIME content

type

From: [email protected] To: [email protected] Subject: Picture of yummy crepe. MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Type: image/jpeg

base64 encoded data ..... ......................... ......base64 encoded data

multimedia datatype, subtype,

parameter declaration

method usedto encode data

MIME version

encoded data

Page 30: 1-1 HTTP and Electronic Mail Services Objectives:  TCP, UDP, HTTP protocols  HTTP clients and servers  Electronic mail

1-30

Mail access protocols

SMTP: delivery/storage to receiver’s server Mail access protocol: retrieval from server

POP: Post Office Protocol [RFC 1939]• authorization (agent <-->server) and download

IMAP: Internet Mail Access Protocol [RFC 1730]• more features (more complex)• manipulation of stored msgs on server

HTTP: Hotmail , Yahoo! Mail, etc.

useragent

sender’s mail server

useragent

SMTP SMTP accessprotocol

receiver’s mail server

Page 31: 1-1 HTTP and Electronic Mail Services Objectives:  TCP, UDP, HTTP protocols  HTTP clients and servers  Electronic mail

1-31

POP3 protocol

authorization phase client commands:

user: declare username pass: password

server responses +OK -ERR

transaction phase, client: list: list message numbers retr: retrieve message by

number dele: delete quit

C: list S: 1 498 S: 2 912 S: . C: retr 1 S: <message 1 contents> S: . C: dele 1 C: retr 2 S: <message 1 contents> S: . C: dele 2 C: quit S: +OK POP3 server signing off

S: +OK POP3 server ready C: user bob S: +OK C: pass hungry S: +OK user successfully logged on

Page 32: 1-1 HTTP and Electronic Mail Services Objectives:  TCP, UDP, HTTP protocols  HTTP clients and servers  Electronic mail

1-32

Email

Mailreader

Maildaemon

SMTP/TCP

Mail gateway

Maildaemon

SMTP/TCP

Mailreader

Maildaemon

Page 33: 1-1 HTTP and Electronic Mail Services Objectives:  TCP, UDP, HTTP protocols  HTTP clients and servers  Electronic mail

1-33

SMTP versus HTTP

SMTP uses persistent connections

SMTP requires message (header & body) to be in 7-bit ASCII

SMTP server uses CRLF.CRLF to determine end of message

Comparison with HTTP: HTTP: pull SMTP: push

both have ASCII command/response interaction, status codes

HTTP: each object encapsulated in its own response msg

SMTP: multiple objects sent in multipart msg