Java Reference
In-Depth Information
/** Utility to write integer values to the output
* stream. **/
void writeNetOutputInt (int i) throws IOException {
fDataOutputStream.writeInt (i);
fDataOutputStream.flush ();
}
/** Utility to write float values to the output stream. **/
void writeNetOutputFloat (float f) throws IOException {
fDataOutputStream.writeFloat (f);
fDataOutputStream.flush ();
}
Once the connection with the client has been established, the run() method
shown below enters a loop where it first waits for a request from the client,
responds to the request, and then waits for the next request. For the simple situation
here, any string received from the client is assumed to be a request for data. So
the worker first tells the client how many data values are coming in the returned
data set. It then generates an array of integer values, where the generation for
each array element comes from a random Gaussian distribution with different
widths and offsets. This data array is then sent to the client just as if it were a set
of data readings from, say, an experimental apparatus.
. ..The run() method in the class DataWorker ...
/** Send data to the client. **/
public void run () {
// If setup fails, end thread processing.
if (!serviceSetup ()) return;
fDataServer.println ( " Client connection and log-in OK -
Begin service... " );
// Lower priority to give main parent and
// other threads some processor time.
setPriority (MIN - PRIORITY);
String client - last - msg ="";
// Begin the loop for communicating with the client.
while (fKeepRunning) {
Search WWH ::




Custom Search