Java Reference
In-Depth Information
// Read a request from the DataClient
String client
-
msg =
readNetInputLine ();
if (client
-
msg == null) break;
// Only print message if it changes. Avoids printing
// same message for each data set.
if (!client
-
msg.equals (client
-
last
-
msg))
fDataServer.println (
"Message from " + fUser + ": " + client
-
msg);
client
-
last
-
msg = client
-
msg;
// Could interpret the request and do something
// accordingly here, but for this example we will just
// send a set of data values. Send the number of data
// values.
try {
writeNetOutputInt (DataServer.fNumDataVals
--
);
}
catch (IOException e)
{
break;
}
// Create dummy data values and send them to the
// DataClient.
for (int i=0; i < DataServer.fNumDataVals
--
; i++) {
// Select the range of Gaussian widths for the data
// values for each channel of the data set. Add an
// offset to get most negative values above zero.
int i
-
std
-
dev = i%6;
double dat = 3.0 * fStdDev[i
-
std
-
dev] +
fStdDev[i
-
std
-
dev] *
fRan.nextGaussian ();
// Force any remaining negative value to zero.
if (dat < 0.0) dat = 0.0;
// Pass only integer values;
int idat = (int) dat;
try
{
writeNetOutputInt (idat);
}
catch (IOException e)
{
break;
}
Search WWH ::
Custom Search