/**
* @see java.lang.Runnable#run()
*/
public void run() {
try {
L2CAPConnection connection = null;
try {
final UUID uuid = new UUID(_uuid);
final LocalDevice local = LocalDevice.getLocalDevice();
updateStatus("[SERVER] Device Address: "
+ local.getBluetoothAddress());
updateStatus("[SERVER] Device Name: "
+ local.getFriendlyName());
updateStatus("[SERVER] Listening for Client...");
// Open a connection and wait for client requests
final L2CAPConnectionNotifier service =
(L2CAPConnectionNotifier) Connector
.open("btl2cap://localhost:" + uuid
+ ";name=" + SERVICE_NAME_L2CAP);
connection = service.acceptAndOpen();
updateStatus("[SERVER] L2CAP connection established");
// Read a message
final byte[] buffer = new byte[1024];
final int readBytes = connection.receive(buffer);
final String receivedMessage =
new String(buffer, 0, readBytes);
updateStatus("[SERVER] Message received: "
+ receivedMessage);
// Send a message
final String message = "\nJSR-82 SERVER says hello!";
updateStatus("[SERVER] Sending message....");
connection.send(message.getBytes());
} finally {
connection.close();
updateStatus("[SERVER] L2CAP session closed");
}
} catch (final IOException ioe) {
BluetoothJSR82Demo.errorDialog(ioe.toString());
}