Internet Computing Workshop
Tom Chothia
• Part 1:
– Summary how Web pages, JavaScript, Servlets and JSP are related.
– How to run your own Servlets and JSP in
Netbeans
• Part 2
– Peer to Peer Systems.
– Very high level overview of the design of Napster,
Gnutella and Bittorrent.
– P2P case studies, BBC ’ s iPlayer.
• Web Pages:
– HTML file passed via HTTP.
• JavaScript
– Code in HTML file, runs on client
• Servlets
– Server code that generates HTML file.
• JavaServer Pages
– Java code in HTML that runs on the server.
Server
HTML
HTTP GET
HTTP file
Client
HTML
Display
HTML file
• HTML is very basic.
• JavaScript is a simple scripting language.
• You can put into HTML web pages.
• It runs on the client.
Server
HTML&JS
HTML +
J.S. file
HTTP GET
HTTP file
Client
HTML&JS
JS interpreter
Display
• Sometimes you don’t want to run code on the client.
• The webpage doesn’t have to be a file.
• A servlet is Java code that runs on the server to handle a request from the client.
• Servlet = a little be of a server.
• The javax.servlet.http.HttpServlet class lets you build a servlet to handle web page request.
• When someone requests the page the doGet method is called.
• The doGet method must write HTML output.
Server
HTML
HTTP GET
HTTP file
Java code
Servlet: doGet
Client
HTML
Display
• When writing servlets you can end up writing lots of HTML.
• JSP lets you put the Java in a HTML file.
• Great for pages with a lot of HTML and a little Java.
Server
HTML
Java code
Servlet: doGet
HTML +
Java file
HTTP GET
HTTP file
Client
HTML
Display
Language Where
Processed
Web Pages HTML N/A
JavaScript HTML &
JavaScript
Servlets Java
Client
Server
JavaServer
Pages
HTML &
Java
Server
• To run JSP or Servlets you need a
“JSP/Servlets container”.
• This is a web server that can run servlets and compile JSP.
• E.g. Apache TomCat, Glassfish.
• Good IDEs can run these for you.
• Create a Web Application project:
File > New Project… > Java Web > Web Application
• This creates the JSP page: index.jsp
• Edit index.html (it can call other Java code).
• Click Run, to start a web server and open the page in a browser.
• Create a web app, as before.
• Create a servlet file:
File > New File… > Web > Servlet
• Click Next, Next and enter the URL Pattern
– The servlet is run when a client requests this URL.
• Edit the Servlet file. E.g. write the doGet() method.
• Click run to start up the server.
• Enter the URL in the browser to see your page.
Internet Computing Workshop
• Napster:
– The first big file sharing network.
– Online between 1999-2001.
– Central Coordinator.
• Gnutella:
– Most popular file-sharing network in mid 2000s.
– No central coordinator.
– Unstructured Network.
• BitTorrent:
– Lots of little P2P networks.
– Single tracker coordinates each download.
– Rewards up-loaders.
I Peer “A” asks the database for “x”.
H
F
“x”
E
C
“x”?
A,E
E
D
G
B
“x”?
A
“x”?
The database tells “A” which peer has the file.
“A” downloads the file from that peer.
“x”
“A” tells the database it has the file.
Other peers can then download the file from
“A”
In newer networks peers record the
IP address of other peers.
A searcher sends a request to all of it’s “neighbours”.
This is forwarded to all of there neighbours, up to a fixed hops.
A
The search request includes
A’s IP address.
Any peer with the requested file contacts A directly.
Peer “A” may then request the file.
A
Tracker
A
Web Server
T
A
T
Peer “A” wants to share a find.
“A” must find a tracker to coordinate the download.
“A” makes a “torrent” file,
– The name of the file.
– The hash of the data.
– The IP address of the tracker.
“A” must put the torrent somewhere people can find it. E.g., on a web server.
“A” tells the tracker is wants to share the file.
T
B A
Tracker
A ,B
Web Server
T
A
Peer “B” finds the torrent file.
“B” finds the tracker IP and connects to it.
The tracker:
– tells “B” the IP of the file sharers.
– And adds “B” address to the list of sharers
“B” connects to “A” and then gets some pieces of the file.
Tracker
A, B,C
Web Server
T
T
B A
T
C
A,B
T
D
B,C
A
Peer “C” connects in the same way.
“A” will try to hand out different copies of the file.
“A” may disconnect.
“C” may get the rest of the file from “B”.
“D” can connect and the sharing continues without “A”.
• The BBC wants to provide TV programs via the Web.
• Streaming all that data costs a lot.
• Therefore the BBC tried out a peer-to-peer system for downloads.
• They used a centrally controlled coordinator and digital rights management.
The idea is:
• If I’m only downloading then I cost the BBC money
(they pay for bandwidth).
• If I upload as much as I download then I cost the
BBC very little.
• If I upload more than I download then I am providing a service for the BBC.
In theory, a company can save millions.
In fact:
• iPlayer users like to stream TV, not download.
• The P2P system can’t provide the exact information at the exact time to watch live.
• In December 2008 the BBC changed their download service to direct download via HTTP.
Key point: P2P has great potential, but it has it’s problems
• AJAX and other new web systems.