Download presentation
Presentation is loading. Please wait.
Published byAnabel Marsh Modified over 9 years ago
1
CSE 341, S. Tanimoto Java networking- 1 Java Networking Motivation Network Layers Using Sockets A Tiny Server Applets URLs Downloading Images, MediaTracker
2
CSE 341, S. Tanimoto Java networking- 2 Motivation Support distributed model of computation Permit programs to download documents Permit programs to run as Applets Anticipate bandwidth limitations
3
CSE 341, S. Tanimoto Java networking- 3 Network Layers Application Level (FTP, Telnet, etc.) Transport Layer (TCP, UDP, sockets, etc.) Network Layer (Low-level Protocol -- IP, datagrams, etc.) Hardware Layer (Ethernet, TokenRing, X.25, etc.)
4
CSE 341, S. Tanimoto Java networking- 4 Sockets int port=2000; BufferedReader br; PrintWriter pw; ServerSocket ss; Socket sock; ss = new ServerSocket(port); sock = ss.accept(); br = new BufferedReader( new InputStreamReader( (sock.getInputStream()); pw = new PrintWriter( sock.getOutputStream()); System.out.println( br.readLine()); pw.println( " HELLO " ); int port=2000; String host= ” cubist " ; BufferedReader br; PrintWriter pw; Socket sock; sock = new Socket(host,port); br = new BufferedReader( new InputStreamReader( (sock.getInputStream()); pw = new PrintWriter( sock.getOutputStream()); pw.println( " ciao " ); System.out.println( br.readLine()); Server Client
5
CSE 341, S. Tanimoto Java networking- 5 A Tiny Server import java.net.*; import java.io.*; public class TestServer { static int port=2000; static BufferedReader br; static PrintWriter pw; static ServerSocket ss; static Socket sock; public static void main(String [] args) { try { ss = new ServerSocket(port); sock = ss.accept(); br = new BufferedReader(new InputStreamReader( (sock.getInputStream()))); pw = new PrintWriter(sock.getOutputStream()); System.out.println(br.readLine()); pw.println("HELLO"); } catch (IOException e) {System.out.println("Error connecting to port");} } }
6
CSE 341, S. Tanimoto Java networking- 6 Applets Developed to fit a W W W client/server architecture with fat clients Normally applets live “in the browser” Limited permissions (talk only to the hosting server, don’t touch local hard disk). Use applet context as an operating env’t.
7
CSE 341, S. Tanimoto Java networking- 7 URLs Uniform Resource Locator http://cubist.cs.washington.edu/~john/d.lsp?q=hello ftp://ftp.cs.washington.edu/pub/myprog.tar class URL URL u; String mydoc; try { u = new URL("http://www.dom.com/x.html"); } catch (MalformedURLException e) { system.out.println("MalformedURLException for " + filename); return; } try { mydoc = (String) u.getContent(); } catch (IOException e) {}
8
CSE 341, S. Tanimoto Java networking- 8 Downloading Images Java anticipated the download times required to retrieve images. provides the MediaTracker class to keep track of the status of files that are being downloaded. Images can be retrieved with URLs that point to either JPEG or GIF images.
9
CSE 341, S. Tanimoto Java networking- 9 Other Networking Issues Distributed objects: Java serialization and class loaders Security: levels of trust/privileges, signed applets Robustness: Avoiding errors, handling errors Practical distribution of code and data: JAR files Reverse engineering and Intellectual Property protection
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.