Prev | Current Page 79 | Next

Timothy J. Thompson, C Bala Kumar, and Paul Kline

"Bluetooth Application Programming with the Java APIs Essentials Edition"

open("btspp://localhost:" +
"86b4d249fb8844d6a756ec265dd1f6a3");
// Accept a connection from the client
StreamConnection conn = notifier.acceptAndOpen();
// Open the input to read data from
InputStream in = conn.openInputStream();
ByteArrayOutputStream out = new
ByteArrayOutputStream();
// Read the data sent from the client until
// the end of stream
int data;
while ((data = in.read()) != -1) {
out.write(data);
}
// Add the text sent from the client to the Form
f.append(out.toString());
// Close all open resources
in.close();
conn.close();
notifier.close();
} catch (BluetoothStateException e) {
f.append("BluetoothStateException: ");
48 Chapter Three: High-Level Architecture
f.append(e.getMessage());
} catch (IOException e) {
f.append("IOException: ");
f.append(e.getMessage());
}
}
}
To verify the code was properly copied from the book, build the
code using the Wireless Toolkit by pressing the ??????Build??™??™ button. Once
the build succeeds, package the build using the ??????Project->Package->
Create Package??™??™ menu option.
After the HelloServer MIDlet is created, the HelloClient
MIDlet must be written to send the ??????Hello, World??™??™ message to the
server. All the work for the HelloClient MIDlet occurs in the run()
method. The run() method uses the selectServices() method to
discover the HelloServer.


Pages:
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91