Java Reference
In-Depth Information
The loop in the run() method sends a request to the server for the data. The
server first returns a value indicating how many data values it plans to send.
The worker then reads that number of values from the input stream connected
to the server. This set of data is then passed to the parent DataClient via
its setData(int[]) method. This program only expects integer data but you
could easily modify it to obtain floating-point data from the server. The loop in
run() pauses for a given period and then repeats the process.
15.8 Benefits and shortcomings of sockets
Socket communications work well for the exchange of files as seen with the
simple web server in Chapter 14 and for the downloading of data and messages
as discussed in this chapter. However, for more ambitious distributed computing
tasks, such as multiprocessing on several hardware processors, other tools pro-
vide significant advantages. For example, the RMI (Remote Method Invocation)
system allows a program on one machine to invoke a method in an object on
another machine just as if it were a local object. The user does not need to create
any sort of custom protocol as we did for the socket I/O. Object serialization also
becomes a powerful feature in such a system. RMI and CORBA procedures rely
on serialization to pass objects back and forth between platforms within a dis-
tributed program. In Chapters 16-20 we discuss these approaches to distributed
computing.
In Chapter 21 we return to a web-based style of distributing computing with
an introduction to web services. This involves the exchange of data in the form
of XML text documents.
15.9 Web Course materials
Chapter 15 in the Web Course includes the complete code for the DataServer
and DataClient programs discussed above. The DataClient runs as applet
and communicates with the DataServer if it is running on the same host.
The Web Course chapter also includes another example of a scientific
client/server application. The SimServer and SimClient programs demon-
strate how a central server could provide a physics simulation service to clients.
The server assigns to each client its own simulator process and the client can
set up the simulator parameters and run it remotely. Such a simulation service
could be useful, for example, in an experimental collaboration in which a sim-
ulator resides on a central site where it is continually updated. Remote users
then run the simulator with the assurance that they are always using the latest
version.
Search WWH ::




Custom Search