
CISC 370 Lecture Notes for Class No. 21 April 25, 2000

| Course Home | Prev Lect | Next Lect | Example Progs | Exercise Solns | CoreJava Progs Documentation |
Gen'l Docs | Java 2 APIs | Java Glossary | Term Proj Info |
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.
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.
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.)
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