Skip to content

Instantly share code, notes, and snippets.

@iewnait
Created April 18, 2012 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save iewnait/2415653 to your computer and use it in GitHub Desktop.
Save iewnait/2415653 to your computer and use it in GitHub Desktop.
Bluetooth Server example using Bluecove
public class WaitThread implements Runnable{
/** Constructor */
public WaitThread() {
}
@Override
public void run() {
waitForConnection();
}
/** Waiting for connection from devices */
private void waitForConnection() {
// retrieve the local Bluetooth device object
LocalDevice local = null;
StreamConnectionNotifier notifier;
StreamConnection connection = null;
// setup the server to listen for connection
try {
local = LocalDevice.getLocalDevice();
local.setDiscoverable(DiscoveryAgent.GIAC);
UUID uuid = new UUID("d0c722b07e1511e1b0c40800200c9a66", false);
System.out.println(uuid.toString());
String url = "btspp://localhost:" + uuid.toString() + ";name=RemoteBluetooth";
notifier = (StreamConnectionNotifier)Connector.open(url);
} catch (Exception e) {
e.printStackTrace();
return;
}
// waiting for connection
while(true) {
try {
System.out.println("waiting for connection...");
connection = notifier.acceptAndOpen();
System.out.println("After AcceptAndOpen...");
Thread processThread = new Thread(new ProcessConnectionThread(connection));
processThread.start();
} catch (Exception e) {
e.printStackTrace();
return;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment