Presentation is loading. Please wait.

Presentation is loading. Please wait.

HTTP and Sockets Lecture 6

Similar presentations


Presentation on theme: "HTTP and Sockets Lecture 6"— Presentation transcript:

1 HTTP and Sockets Lecture 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 quarter’s exam online
Closed-book 1 8x11 cheat sheet Short-answer

4 Today’s Discussion HTTP Wrap-up Sockets in Java HTTP 1.1 additions
HTTP Proxies Sockets in Java

5 Persistent Connections
HTTP Connections close by Default No need for Content-length, end signaled by EOF (in-band signal) HTTP 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: Solution:
Want multiple web sites hosted on single server Incoming requests must be directed to return appropriate web site’s page Solution: Request includes host name header host:

8 Try This At Home telnet cva.stanford.edu 80 GET / HTTP/1.1
Host:cva.stanford.edu Connection:Keep-Alive GET /group_mtg.html HTTP/1.1 Connection:Close

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

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/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.getInputStream());

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){ }finally{ } 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: < or > could be delineators Pattern and Matcher classes Create pattern Use Matcher class to compare strings to pattern


Download ppt "HTTP and Sockets Lecture 6"

Similar presentations


Ads by Google