Java Reference
In-Depth Information
// This loops until either the connection is broken or
// the stop button or stop key is hit
while (fKeepRunning) {
// Ask the server to send data.
try {
writeNetOutputLine (" send data");
}
catch (IOException e) {
break;
}
// First number sent from server is an integer that
// gives the number of data values to be sent.
try {
num - channels = readNetInputInt ();
}
catch (IOException e) {
break;
}
if (num - channels! = fNumChannels) {
fNumChannels = num - channels;
fDataClient.println (
" Number data channels =" + fNumChannels);
}
if (fNumChannels < 1) {
fDataClient.println (" no data");
break;
}
// Create an array to hold the data if not available
if (fData == null || fNumChannels ! = fData.length)
fData = new int[fNumChannels];
for (int i=0; i < fNumChannels; i++) {
try {
fData[i] = readNetInputInt ();
// Pass the data to the parent program to do
// with as it wants
fDataClient.setData (fData);
}
catch (IOException e) {
 
Search WWH ::




Custom Search