1 / 9

Java Networking

Java Networking. Motivation Network Layers Using Sockets A Tiny Server Applets URLs Downloading Images, MediaTracker. Motivation. Support distributed model of computation Permit programs to download documents Permit programs to run as Applets Anticipate bandwidth limitations.

parson
Download Presentation

Java Networking

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Java Networking • Motivation • Network Layers • Using Sockets • A Tiny Server • Applets • URLs • Downloading Images, MediaTracker 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 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.) CSE 341, S. Tanimoto Java networking-

  4. Sockets Server Client 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()); 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");} } } 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. 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) {} 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. 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 CSE 341, S. Tanimoto Java networking-

More Related