1 / 13

Networking

Networking. Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung University. Networking. Client/Server Communications Serving Multiple Clients Applet Clients Viewing HTML Pages Retrieving Files from Web Servers. Single-block App.

dallon
Download Presentation

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. Networking Instructors: Fu-Chiung Cheng (鄭福炯) Associate Professor Computer Science & Engineering Tatung University

  2. Networking • Client/Server Communications • Serving Multiple Clients • Applet Clients • Viewing HTML Pages • Retrieving Files from Web Servers

  3. Single-block App. • hard to develop • difficult to maintain • Client/Server arch • difficult to • administration • Multi-tier arch. • Browser-based • very power with • EJB

  4. Client/Server Communications

  5. A Client/Server Example • Objective: • Write a client to send data to a server. • The server receives the data, uses it to produce a result, and then sends the result back to the client. • The client displays the result on the console. • In this example, the data sent from the client is the radius of a circle, and the result produced by the server is the area of the circle. • Programs: Client.java & Server.java

  6. Example client.java & server.java Server Code Run Client Code Run Note: Run Server first, then Client. Press Ctrl+C to close the window.

  7. Serving Multiple Clients Server for Multiple Clients Run Server Run Client Note: 1. Run Server first, then Client. Press Ctrl+C to close the window. 2. Programs: Client.java & MultiThreadServer.java

  8. Applet Clients Due to security constraints, applets can only connect to the host from which they were loaded. Therefore, the HTML file must be located on the machine on which the server is running. Server Code Client Code Run Note 1. run java RegServer in JBuilder. 2. Goto jbBook dir and run appletviewer regClient.html in the second DOS window.

  9. Viewing HTML Pages • Given the URL of the page, a Web browser can view an HTML page—for example, http://www.sun.com. • HTTP (Hypertext Transfer Protocol) is the common standard used for communication between a Webserver and the Internet. You can open a URL andview a Web page in a Java applet. • A URL is a description of a resource location on the Internet. • Java provides a class—java.net.URL—to manipulate URLs.

  10. Creating a URL Instance The following statement creates a Java URL object: try { URL location = new URL("http://www.sun.com"); } catch(MalformedURLException e) { } ViewingWebPages Run If necessary, click the Run button to access the DOS prompt. Using a JDK1.1-enabled Web browser (such as the HotJava Browser), open the file ViewingWebPages.html and enter a URL. (Begin the URL with http://.) This applet cannot run using the Applet Viewer utility.

  11. Retrieving Filesfrom Web Servers The following figure shows the process by which an applet reads the files on the Web server:

  12. Example Retrieving Remote Data Files • Objective: Compute and display student exam scores. The example reads the file from a Web server. RetrievingRemoteFile Run If necessary, click the Run button to access the DOS prompt. Using a Web browser (such as the HotJava Browser), enter the following URL:http://www.ipfw.edu/kt2/liangy/web/java/RetrievingRemoteFile.html

  13. The Web Server • You need to place three files on the Web server: • RetrievingRemoteFile.class • RetrievingRemoteFile.html • in.dat • For convenience, place them in one directory.

More Related