client
Class Client

java.lang.Object
  extended by client.Client

public class Client
extends java.lang.Object

Class Client is a simple illustration of a client that communicates with a remote server using RMI. The client provides server-setup and computation methods, detailed descriptions of which are given in the method documentation.

The main method of the client accepts two command-line arguments. The first argument is the name of the host on which the server is running. The host name may be suffixed with a colon-delimited port number. If the port number is not present, the rmiregistry on the remote host is assumed to be running on the well-known port 1099. So, e.g., a legal hostname could be "waldorf.csc.calpoly.edu" or "waldorf.csc.calpoly.edu:1098", the latter selecting alternate registry port 1098.

The second command-line argument is an optional flag indicating if the client's GUI should be displayed when it runs. If the argument is missing, the default behavior is to display the GUI. If the second argument is "-nd", then no GUI display is shown. Using the "-nd" argument is useful when the client is run in a context where there is no support for a Java GUI display, for example, running the client on a UNIX machine like waldorf when logged into waldorf via telnet from a Windows PC.

See the Server class for a description of the server that this client uses.


Field Summary
protected static boolean displayOn
          True if the display is on, i.e., the 2nd command-line arg != "-nd"
protected static ServerInterface server
          The remote server class; note the use of the interface type in the declaration, which means that the server implementation need not be (and typically is not) on the client machine.
protected static javax.swing.JTextField textField
          The text field that displays the result computed by the server; the result is printed to stdout instead of this text field if the GUI display is not active
 
Constructor Summary
Client()
           
 
Method Summary
protected static void establishCommunication(java.lang.String hostname)
          Establish communication with the server running on the given hostname.
static void main(java.lang.String[] args)
          Get the hostname from command-line argument, exiting if there is none.
protected static void performComputation()
          Call the following methods on the remote server: receiveClientInput compute getServerOutput Display the resulting server output in the display window, or write the output to stdout if the display is not on.
protected static void setupDisplay(java.lang.String hostname)
          Set up the display as a JFrame with a labeled text field.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

server

protected static ServerInterface server
The remote server class; note the use of the interface type in the declaration, which means that the server implementation need not be (and typically is not) on the client machine.


textField

protected static javax.swing.JTextField textField
The text field that displays the result computed by the server; the result is printed to stdout instead of this text field if the GUI display is not active


displayOn

protected static boolean displayOn
True if the display is on, i.e., the 2nd command-line arg != "-nd"

Constructor Detail

Client

public Client()
Method Detail

establishCommunication

protected static void establishCommunication(java.lang.String hostname)
Establish communication with the server running on the given hostname. As explained in the class documentation, the hostname may be suffixed with colon-delimited port number. The hostname is used to create a server name of the form "//hostname/Server". See the documentation for the server.Server.setupServer method for a explanation of this server-name syntax.


setupDisplay

protected static void setupDisplay(java.lang.String hostname)
Set up the display as a JFrame with a labeled text field. The hostname input is the command-line argument from main.


performComputation

protected static void performComputation()
Call the following methods on the remote server:
  1. receiveClientInput
  2. compute
  3. getServerOutput
Display the resulting server output in the display window, or write the output to stdout if the display is not on. The actual computation is very simple -- a client data value of 10 is sent to the server, to which the server simply adds 1, resulting in an output of 11.


main

public static void main(java.lang.String[] args)
Get the hostname from command-line argument, exiting if there is none. Then call the methods to establish communication with server and perform the simple computation.