CISC 370 Lecture Notes for Class No. 21 April 25, 2000
JAVA Client-Side Networking

Course Home Prev Lect Next Lect Example Progs Exercise Solns
CoreJava Progs
Documentation
Gen'l Docs Java 2 APIs Java Glossary Term Proj Info

Assignment

Reading:
Horstmann & Cornell, Vol II, chap 3, Networking, pp. 147-174
Assignment: Mile post 1 for the term projects is due Thursday.

Today's Lecture Topics

  1. Topics for the Remainder of the Semester

    • Networking, H&C vol II, chap 3
    • Remote Method Invocation (RMI), H&C vol II, chap 5
    • Animation and Threads, H&C vol II, chap 1
    • Exceptions, Additional GUI components, input/output from applets, Java data structures, etc.

  2. Java Networking

    Over the next few lectures we will cover networking and remote method invocation in Java. This is one of the most beautiful parts of the the Java API library. We will not assume any knowledge of networking.

  3. Using telnet to connect to the server for the Cesium atomic clock for the time-of-day service at the National Institute of Standards and Technology (NIST) in Boulder, Colorado. By convention, the time-of-day service is always attached to port 13. To do this from a Unix machine, type

    telnet time-A.timefreq.bldrdoc.gov 13

    or use the GUI for telnet from a Windows machine.

    The machine we execute this command on is the client machine in this transaction.

  4. Now a Java program that connects to the time-of-day server and prints the data returned by the server. This is program discussed on pp. 150-1 of H&C vol II. It is a Java analog to the telnet command above.
    (A programming style comment: The loop in H&C's code has been changed by BFC with the belief that the revision is simpler to understand and debug than the original
         boolean more = true;
         while (more){
             String line = in.readLine();
             if ( line == null ) more = false;
             else
                 System.out.println(line);
         }
         
    Always try to include the terminating condition directly into the while statement. Many programmers use "flags" like this to terminate loops and such constructions almost always lead to inferior code. From the loop given in the revision, one can always be assured that line == null when the loop terminates, an important fact for reasoning about the correctness of the code. Another problem with the original code is that line is redeclared each time that the loop is performed therby wasting (a bit of) time and space.)

  5. Handling delays with networking code

    Delays and other networking problems are a fact of life that with which networking code must deal. This example, from H&C vol II, pp. 153-4 as revised by BFC, uses a separate thread to open the network socket, a thread that will timeout after a set time if the socket cannot be opened within the duration. It uses the setSoTimeout() method from Socket class to time out when trying to read from the socket after the socket is opened.

Back to the CISC 370 homepage.

This page has been accessed times since 25 April 2000.

Corrections, suggestions and comments to Bob Caviness

Copyright 1999 B. F. Caviness