HTTP and Sockets Lecture 6 - PowerPoint PPT Presentation

1 / 26
About This Presentation
Title:

HTTP and Sockets Lecture 6

Description:

HTTP Proxies. Sockets in Java. Persistent Connections. HTTP 1.0 -- Connections close by Default ... HTTP Proxy Servers 'Middlemen' between clients and servers ... – PowerPoint PPT presentation

Number of Views:62
Avg rating:3.0/5.0
Slides: 27
Provided by: kelly113
Category:
Tags: http | lecture | proxy | sockets

less

Transcript and Presenter's Notes

Title: HTTP and Sockets Lecture 6


1
HTTP and SocketsLecture 6
  • cs193i Internet Technologies
  • Summer 2004
  • Stanford University

2
Administrative Stuff
  • Lab 2 due today
  • HW 2 due July 21
  • Midterm Monday, July 19, in class

3
Midterm
  • In class, Monday, July 19
  • Previous quarters exam online
  • Closed-book
  • 1 8x11 cheat sheet
  • Short-answer

4
Todays Discussion
  • HTTP Wrap-up
  • HTTP 1.1 additions
  • HTTP Proxies
  • Sockets in Java

5
Persistent Connections
  • HTTP 1.0 -- Connections close by Default
  • No need for Content-length, end signaled by EOF
    (in-band signal)
  • HTTP 1.1 -- Persistent by Default
  • Must use Content-length

6
Chunked-Transfer Encoding
  • Problem Content-length costly for server
  • May not know if generated dynamically
  • Solution
  • Server omits Content-Length
  • Transfer-encoding chunked
  • Send Data in Chunks, Prefixed by length in Hex
  • End is marked with Chunk Length 0

7
HTTP 1.1 Virtual Hosts
  • Problem
  • Want multiple web sites hosted on single server
  • Incoming requests must be directed to return
    appropriate web sites page
  • Solution
  • Request includes host name header
  • http//www.foo.com
  • hostwww.foo.com

8
Try This At Home
  • telnet cva.stanford.edu 80
  • GET / HTTP/1.1
  • Hostcva.stanford.edu
  • ConnectionKeep-Alive
  • GET /group_mtg.html HTTP/1.1
  • Hostcva.stanford.edu
  • ConnectionClose

9
HTTP Proxy Servers
  • "Middlemen" between clients and servers
  • May "rewrite" HTTP requests and responses

Proxy Server
Looks like a server sending responses
Looks like a client making requests
10
Why Proxy Servers?
  • Content filtering
  • Packet filter
  • Prevent children from accessing sites
  • Used to contact server in special way
  • Firewall or circuit relay
  • Security
  • Rewrite content
  • Swedish chef
  • Redirect requests
  • Content router
  • To improve performance
  • Logging activity

11
Why Proxy Servers?
Web cache is also a type of proxy!
RT latency reduced
12
Why Proxy Servers?
Content Router
13
Why Proxy Servers?
Content Router
14
Why Content Routers?
Content Router
15
Why Proxy Servers?
Content Router
16
Why Proxy Servers?
Anonymizer
17
Why Proxy Servers?
Translation
18
Why Proxy Servers?
Translation
http//translate.google.com/translate?hlensles
uhttp//espanol.yahoo.com/prev/search3Fq3Dspa
nish26hl3Den26lr3D26ie3DUTF-8
19
Requests via Proxy
  • Client must realize talking to proxy
  • Request header
  • GET path HTTP/1.0
  • Client must use absolute path!
  • GET / HTTP/1.0
  • GET http//www.yahoo.com/ HTTP/1.0

20
Five Minute Break
21
Sockets in Java (Client)
  • java.net.socket
  • Create Socket
  • Socket c new Socket(hostname, port)
  • OR
  • Socket c new Socket(IP addr, port)

22
Reading/Writing to Sockets
  • Just like performing file I/O in Java
  • Create input/output streams to read/write to/from
    socket
  • Output example PrintWriter class
  • new PrintWriter(c.getOutputStream(), true)
  • Input example BufferedReader class
  • new BufferedReader(new InputSreamReader(c.getInput
    Stream())

23
Sockets in Java (Server)
  • Create ServerSocket
  • Socket listen new ServerSocket(port)
  • Create Socket
  • ServerSocket.accept()
  • Blocks until connection established
  • Socket s new listenSocket.accept()
  • Create input/output streams
  • Close when finished

24
Exceptions
  • Sockets throw exceptions when something goes
    wrong
  • UnknownHostExcpetion
  • Handle using try/catch pairs
  • try
  • (statement)
  • catch(ExceptionType e)
  • (statement)
  • finally
  • (statement)
  • Can have multiple catch clauses for handling
    different exceptions

25
URL Class
  • Automatically decomposes string into parts
  • getHost()
  • getPort()
  • getProtocol()
  • getFile() // path

26
What do you do with this stuff?
  • StringTokenizer class
  • Allows you to grab tokenized strings one at a
    time
  • You can specify what delineates strings
  • Example could be delineators
  • Pattern and Matcher classes
  • Create pattern
  • Use Matcher class to compare strings to pattern
Write a Comment
User Comments (0)
About PowerShow.com