Advertisement
Guest User

Untitled

a guest
Oct 31st, 2012
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. public class BTSend
  2. {
  3.  
  4. public static final UUID uuid = new UUID("27012f0c68af4fbf8dbe6bbaf7aa432a", false);
  5. public static final String name = "NXTBridge";
  6. public static final String url = "btspp://localhost:" + uuid //the service url
  7. + ";name=" + name
  8. + ";authenticate=false;encrypt=false;";
  9.  
  10. static LocalDevice ipod_local = null;
  11. static StreamConnectionNotifier ipod_server = null;
  12. static StreamConnection ipod_conn = null;
  13.  
  14.  
  15.  
  16.  
  17. public static void main(String[] args)
  18. {
  19.  
  20. System.out.println("Beginning Server");
  21. try {
  22. System.out.println("Setting device to be discoverable...");
  23. ipod_local = LocalDevice.getLocalDevice();
  24. ipod_local.setDiscoverable(DiscoveryAgent.GIAC);
  25. System.out.println("Start advertising service...");
  26. ipod_server = (StreamConnectionNotifier)Connector.open(url);
  27. System.out.println("Waiting for incoming connection...");
  28. ipod_conn = ipod_server.acceptAndOpen();
  29. System.out.println("Client Connected...");
  30. DataInputStream din = new DataInputStream(ipod_conn.openInputStream());
  31. while(true)
  32. {
  33. String cmd = "";
  34. char c;
  35. while (((c = din.readChar()) > 0) && (c!='\n') ){
  36. cmd = cmd + c;
  37. }
  38. System.out.println("Received " + cmd);
  39. }
  40.  
  41. } catch (Exception e) {System.out.println("Exception Occured: " + e.toString());}
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement