Created
April 18, 2012 18:32
-
-
Save iewnait/2415653 to your computer and use it in GitHub Desktop.
Bluetooth Server example using Bluecove
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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