|
| |
"Wireless J2ME Applications with Java and Bluetooth - Part 2 of 2"
Vol. 7, Issue 9, p. 54
Listing 1
...
// lets name our variables
StreamConnectionNotifier notifier = null;
StreamConnection sconn = null;
LocalDevice localdevice = null;
ServiceRecord servicerecord = null;
// step #1
// the String url will already be defined with the
// correct url parameters
notifier = (StreamConnectionNotifier)Connector.open(url);
// step #2
// we will get the LocalDevice if not already done so
localdevice = LocalDevice.getLocalDevice();
servicerecord = localdevice.getRecord(notifier);
// step #3 is optional
// step #4
// this step will block the current thread until a client responds
// this step will also cause the service record to be
// stored in the SDDB
notifier.acceptAndOpen();
// step #5
// just wait...
// assume the client has connected and you are ready to exit
// step #6
// this causes the service record to be removed
// from the SDDB
notifier.close();
Listing 2
...
// let's name our variables
StreamConnectionNotifier notifier = null;
StreamConnection con = null;
LocalDevice localdevice = null;
ServiceRecord servicerecord = null;
InputStream input;
OutputStream output;
// let's create a URL that contains a UUID that
// has a very low chance of conflicting with anything
String url =
"btspp://localhost:0011223344556677889900AABBCCDDEEFF;name=serialconn";
// let's open the connection with the url and cast it into a
StreamConnectionNotifier
notifier = (StreamConnectionNotifier)Connector.open(url);
// block the current thread until a client responds
con = notifier.acceptAndOpen();
// the client has responded, so open some streams
input = con.openInputStream();
output = con.openOutputStream();
// now that the streams are open, send and receive some data
|
|
All Rights Reserved
Copyright © 2004 SYS-CON Media, Inc.
E-mail: info@sys-con.com
Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.
|