Java Reference
In-Depth Information
}
}
// Send message back to the text area in the frame.
fDataServer.println (fUser + " has disconnected.");
// Do any other tasks for ending the worker.
signoff ();
} // run
The DataWorker class could be modified to obtain real data in various ways.
Forexample, a sensor might generate a file that the worker could read and forward
to the client.
15.6 The DataClient
The DataClient , shown running in Figure 15.3, is an applet that makes a socket
connection to DataServer ,grabs data from the server, and displays it in two
histograms. Such a client program could serve as a data monitoring tool. From a
remote location you could examine samples of data as it is produced during an
experiment in a manner that helps to spot anomalies or malfunctions. The data
would normally be saved to disk files on the server machine for full analysis later
but the monitor helps to prevent the taking of flawed data.
The main job of DataClient is to create an interface for the user to initiate
and control communications with the server. It provides fields to specify the
server's host address, a user name, and which channel in the data set to plot in
the lower histogram. Here we are assuming that the data comes in as a set of
readings or channels. For example, perhaps there are readings from 20 sensors in
each data set. We refer here to a particular reading in the set of 20 as a channel.
The top histogram displays the values for each data set as it arrives. (That is,
bin 0 in the histogram corresponds to the value in element 0 of the data array,
bin 1 to element 1, and so forth.) At a glance this histogram indicates whether
some channels are missing data. The user can also select a particular channel to
display its distribution of values in the bottom histogram. A set of buttons starts
the process, clears the histograms, and exits the program.
Here we show a large snippet from the DataClient applet, skipping the
init() method that creates the interface. A click on the Start button
on the interface leads to the invocation of the start() method, which in
turn invokes the connect() method that makes the socket connection to the
server.
 
Search WWH ::




Custom Search