Download as pdf or txt
Download as pdf or txt
You are on page 1of 21

Trying out HTTP (client side) for yourself

1. Telnet to your favorite Web server:


telnet ic.payap.ac.th 80 Opens TCP connection to port 80
(default HTTP server port) at ic.payap.ac.th
Anything typed in sent
to port 80 at ic.payap.ac.th

2. Type in a GET HTTP request:


GET /university/about.php HTTP/1.1 By typing this in (hit carriage
Host: ic.payap.ac.th return twice), you send
this minimal (but complete)
GET request to HTTP server

3. Look at response message sent by HTTP server!

32 ©Vaide Narvaez
User-server interaction: cookies
Many major Web sites Example:
use cookies   Susan always access
Four components: Internet from home PC
  1) cookie header line of   visits specific e-commerce
HTTP response message site for first time
  2) cookie header line in
  when initial HTTP
HTTP request message
requests arrives at site,
  3) cookie file kept on user’s
site creates:
host, managed by user’s
browser   unique ID
  4) back-end database at   entry in backend database

Web site for ID

33 ©Vaide Narvaez
Cookies: keeping “state” (cont.)
client server
ebay 8734
usual http request msg
Amazon server
cookie file usual http response creates ID
Set-cookie: 1678 1678 for user create
ebay 8734 entry
amazon 1678
usual http request msg
cookie: 1678 cookie- access
specific
one week later: usual http response msg action backend
database
access
ebay 8734
usual http request msg
amazon 1678
cookie: 1678 cookie-
spectific
usual http response msg action
34 ©Vaide Narvaez
Cookies (continued)
What cookies can bring: Cookies and privacy:
  authorization   cookies permit sites to
  shopping carts learn a lot about you
  recommendations   you may supply name and e-
mail to sites
  user session state (Web e-
mail)
How to keep “state”:
  protocol endpoints:
maintain state at sender/
receiver over multiple
transactions
  cookies: http messages
carry state

35 ©Vaide Narvaez
Web caches (proxy server)
Goal: satisfy client request without involving origin server

  user sets browser: Web origin


server
accesses via cache
  browser sends all HTTP Proxy
requests to cache server
client
  object in cache: cache
returns object
  else cache requests object
from origin server, then
returns object to client
client

36 ©Vaide Narvaez
More about Web caching
  cache acts as both client and Why Web caching?
server   reduce response time for
  typically cache is installed by client request
ISP (university, company,   reduce traffic on an
residential ISP) institution’s access link.
  Internet dense with caches:
enables “poor” content
providers to effectively
deliver content (but so does
P2P file sharing)

37 ©Vaide Narvaez
Conditional GET
Goal: don’t send object
server
if cache has up-to-date cache
cached version HTTP request msg
If-modified-since:
  cache: specify date of <date>
object
not
cached copy in HTTP
HTTP response modified
request HTTP/1.0
  If-modified-since: <date> 304 Not Modified

  server: response contains


no object if cached copy HTTP request msg
If-modified-since:
is up-to-date: <date> object
  HTTP/1.0 304 Not modified
Modified HTTP response
HTTP/1.0 200 OK
<data>
38 ©Vaide Narvaez
File Transfer: FTP
FTP: the file transfer protocol

FTP file transfer


FTP FTP
user client server
interface
user
at host remote file
local file system
system

  transfer file to/from remote host


  client/server model
  client: side that initiates transfer (either to/from remote)
  server: remote host

40 ©Vaide Narvaez
FTP: separate control and data connections
TCP control connection
  FTP client contacts FTP server at port 21
port 21, TCP is transport protocol
  client authorized over control TCP data connection
connection FTP port 20 FTP
client server
  client browses remote directory by
sending commands over control ❒  server opens another TCP data
connection. connection to transfer another
  when server receives file transfer file.
command, server opens 2nd TCP ❒  control connection: “out of band”
connection (for file) to client
❒  FTP server maintains “state”:
  after transferring one file, server current directory, earlier
closes data connection. authentication

41 ©Vaide Narvaez
E-mail

SMTP, POP3, IMAP


Electronic Mail outgoing
message queue
user mailbox
user
Three major components: agent
  user agents mail
user
  mail servers server
agent
  simple mail transfer protocol: SMTP
SMTP mail
server user
User Agent SMTP agent

  a.k.a. “mail reader/client”


SMTP
  composing, editing, reading mail mail user
messages server agent
  e.g., MS Outlook, Mozilla
Thunderbird user
agent
  outgoing, incoming messages
user
stored on server agent

43 ©Vaide Narvaez
Electronic Mail: mail servers
user
Mail Servers agent
  mailbox contains incoming mail
user
messages for user server
agent
  message queue of outgoing (to be SMTP
sent) mail messages mail
server user
  SMTP protocol between mail
SMTP agent
servers to send email messages
  client: sending mail server SMTP
mail user
  “server”: receiving mail server agent
server

user
agent
user
agent
44 ©Vaide Narvaez
Electronic Mail: SMTP
  uses TCP to reliably transfer email message from client to server,
port 25
  direct transfer: sending server to receiving server
  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

45 ©Vaide Narvaez
Scenario: Alice sends message to Bob
1) Alice uses UA to compose 4) SMTP client sends Alice’s
message to message over the TCP
bob@someschool.edu connection
2) Alice’s UA sends message to her 5) Bob’s mail server places the
mail server; message placed in message in Bob’s mailbox
message queue 6) Bob invokes his user agent to
3) Client side of SMTP opens TCP read message
connection with Bob’s mail
server

1 mail
mail
server user
user server
2 agent
agent 3 6
4 5

46 ©Vaide Narvaez
Sample SMTP interaction
S: 220 hamburger.edu
C: HELO crepes.fr
S: 250 Hello crepes.fr, pleased to meet you
C: MAIL FROM: <alice@crepes.fr>
S: 250 alice@crepes.fr... Sender ok
C: RCPT TO: <bob@hamburger.edu>
S: 250 bob@hamburger.edu ... Recipient ok
C: DATA
S: 354 Enter mail, end with "." on a line by itself
C: Do you like ketchup?
C: How about pickles?
C: .
S: 250 Message accepted for delivery
C: QUIT
S: 221 hamburger.edu closing connection

47 ©Vaide Narvaez
Try SMTP interaction for yourself:
  telnetmail.payap.ac.th 25
  see 220 reply from server
  enter HELO, MAIL FROM, RCPT TO, DATA, QUIT
commands
  above lets you send email without using email client
(reader)

48 ©Vaide Narvaez
SMTP: final words
  SMTP uses persistent connections Comparison with HTTP:
  SMTP requires message (header &
  HTTP: pull
body) to be in 7-bit ASCII
  SMTP: push
  SMTP server uses CRLF.CRLF to
determine end of message   both have ASCII command/
response interaction, status codes

  HTTP: each object encapsulated in


its own response msg
  SMTP: multiple objects sent in
multipart msg

49 ©Vaide Narvaez
Mail access protocols
SMTP SMTP access user
user
agent protocol agent

sender’s mail receiver’s mail


server server
  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: gmail, Hotmail, Yahoo! Mail, etc.

50 ©Vaide Narvaez
telnet mail.payap.ac.th 110
POP3 protocol S: +OK POP3 server ready
C: user bob
S: +OK
authorization phase C: pass hungry
  client commands: S: +OK user successfully logged on
  user: declare username
C: list
  pass: password
S: 1 498
  server responses S: 2 912
  +OK S: .
  -ERR C: retr 1
S: <message 1 contents>
transaction phase, client: S: .
  list: list message numbers C: dele 1
  retr: retrieve message by C: retr 2
number S: <message 1 contents>
  dele: delete S: .
C: dele 2
  quit C: quit
S: +OK POP3 server signing off
51 ©Vaide Narvaez
POP3 (more) and IMAP
More about POP3 IMAP
  Previous example uses   Keep all messages in one
“download and delete” place: the server
mode.   Allows user to organize
  Bob cannot re-read e-mail messages in folders
if he changes client   IMAP keeps user state
  “Download-and-keep”: across sessions:
copies of messages on   names of folders and
different clients mappings between message
IDs and folder name
  POP3 is stateless across
sessions

52 ©Vaide Narvaez

You might also like