Sample Applications
Distinct ONC RPC/XDR Toolkit
Version 5.0 comes with some source code samples.
To run the demo of Distinct ONC RPC/XDR for Java,
you must first install the distribution files (Java class files) as described on
the previous page. Please make sure that the CLASSPATH variable is updated
properly as described in Start.html file.
All the samples are located in a
subfolder named "samples" under the installation folder of the toolkit.
The following is a list of the
samples included:
ECHO
This sample should be looked at to understand the basic concepts of the Distinct ONC
RPC/XDR Toolkit for Java. There is a sample client called "echoclient" and
server called "MyServer". The client sends a number to the
server, and the server subtracts one from it and sends it back to the client,
the client displays the number on screen.
If you run the server and the client on same machine,
follow these steps:
1. To run the server: Go to the folder %Distinct Toolkit Installation%/samples/echo,
and
from the command line run:
java MyServer
2. From the command line run the client by typing
java echoclient localhost [
number ]
where number is any integer, for example 4, 10 or 3345.
SUM
This in an enhancement to ECHO sample. Here instead of only one argument,
two arguments are being passed to the server. The server returns the sum
of the numbers and the client displays it on the console.
STRCNT
In this sample, the passing of string datatype is shown. The
client
sends a string to the server, and the server returns the length of the
string.
COUNT
Start the demo client application by running "couTest.class"
with your Java interpreter. The demo makes three RPC calls to increment the
counter on the server and three RPC calls to decrement the counter. After
each call the current value of the counter is displayed.
Applet: Start the demo client
applet by opening testapp.html in your browser. The demo page contains
an instance of the demo applet which will invoke the server each time
you click on it. The applet reports the reply of each call as well as
any error conditions.AUTH
This is the COUNT example with the
addition of AUTH_DES authentication. To
run the sample first run the server. For simplicity in this sample we
are hardcoding the user name and password. When the dialog box to enter the user
name and password is displayed, eneter "user3" for both the username and
password.
Once the server is running, run the client and it
will ask for the username and password. After providing the correct username and
password (user3 in this sample), the sample does the same operations as the COUNT example.
PORTMAPPER
The "PmapTest.class" sample program contacts the port mapper
on the local machine and checks if the demo server is currently
running. If the demo server is registered with the local port mapper,
then the sample program will display the port on which the server is
running.
BROADCAST
The "BroadcastTest.class" sample program demonstrates how to
use broadcast RPCs to locate a server. The sample keeps sending
broadcast messages to all NFS servers on the local subnet until it
receives an answer. It then prints the host name and IP address of the
responding server.
RSTAT
This sample connects to any Unix host and gets information about the
length of time the system has been up and the load average of the system.
RUSERS
This sample connects to a Unix host and gets the information about the
users on that host.
STREAM
This sample illustrates how to pass a STREAM of data from a client to the server.
CALLBACK
In RPC programming it is sometimes useful to use callbacks. This frees the
client to do other tasks while it is waiting for the server to return the
results of its previous call. When the server has processed the request, it will
make a client call to the "client" to give it its results.
RPCINFO
This sample queries RPCBIND or Portmapper on a specified host to get
the information about RPC services currently running on that host.
THREAD
This sample illustrates how to implement a multithreaded server. For comparisons, the same server may be run single or multithreaded.
This example is based on the COUNT example. First, start the server either single threaded with java docount s
or multithreaded with
java docount m (You will see different behavior depending on whether you run a single or a multithreaded server. This is intentional and
correct because the internal
counter is NOT protected against concurrent access.)
Then in at least two other windows start java testprg localhost inc or java testprg localhost dec
The increment and decrement RPC calls include an internal sleep delay to illustrate the effects of concurrency. Select the UDP or TCP protocol by
removing the comment in the appropriate lines.
Note that in the single threaded version all RPCs are put in a queue (and take longer to process) while in the multithreaded version they are
processed concurrently. This will also be displayed by the server. It prints a line on each call and it reports
the thread number currently active.
SSL
This sample is an extension of COUNT sample with SSL added to it for
secure data transactions.
To run the sample use docount_ssl.class as the server file and testprg.class as the client file.
Before running this example, you should be
familiar with JSSE and how it works. The example requires that JSSE is set up
correctly on both the client and the server systems. The sample makes use of a
certificate created for the purpose of this sample and is not in the default
Trust store. The sample hard codes the password for simplicity. To run the
sample once all the pieces have been set up, enter:
java -Djavaz.net.ssl.trustStore=samplecacerts
testprg localhost inc
Note that the use of SSL is subject
to US Export regulations. For information about these refer to the your JSSE
supplier.
UNSIGNED
Java does not support Unsigned data
types. This example shows a work around for this when you have an existing RPC
server that uses an unsigned integer.
We will use Long data type of Java to keep the unsigned integer by using the necessary number of bits and ignoring the
rest of the bits.
In this example we have a simple implementation of a client and a server similar to the echo
sample, but here the server, after receiving a number from client,
sends the result of the operation back to the client, after computing
the square of the original number.
To implement the unsigned integer, we have a file called U_INT.java which contains a Class
U_INT to wrap a long integer.
In the XDR file, we change the references of unsigned integer to U_INT and do the same in the client and server program.
For more information on working around unsigned datatypes see how
to work around unsigned data types.
XML
This is an example of how to use the XML features in this product. The same
sample application is used to illustrate three different senarios:
| 1 |
Using a built-in HTTP server |
| 2 |
Using a Servlet |
| 3 |
Using a proxy |
The example is described in greater
detail in the XML Extensions.
The XDR definition file is:
admin.x - the XDR interface specification
The files generated by JRPCGEN are:
admin.java - used to create ONC RPC client (not implemented in this sample)
admin_xml.java - provides the same RPC call interface to the client application
as the standard client class Admin.java but it calls using the XML-RPC protocol.
adminServer.java - used to create MemberServerONC.java
stat.java, member.java, member_list.java, Search_1_argument.java and
Search_1_return.java are the class definition files used in the XDR definition.
The sample application files are:
MemberServer.java - the standalone server (ONC RPC and XML-RPC (port 8080))
MemberServerONC.java - an ONC RPC Server to be used as an example of using a
proxy to turn an existing ONC RPC server into a Web-service
MemberClient.java - the XML-RPC client
MemberProxy.java - the XML-RPC to ONC RPC proxy (gateway) on port 8081
MemberServlet.java - the standalone server as servlet (only XML-RPC, for integration in a servlet framework)
MemberProxyServlet.java - the XML-RPC to ONC RPC proxy (gateway) as servlet (for integration in a servlet framework)
|