Example #1
0
  // start server
  public void startServer() throws IOException {

    // Create a UUID for SPP
    UUID uuid = new UUID(Config.uuid, true);
    System.out.println(uuid.toString());
    // Create the servicve url
    String connectionString = "btspp://localhost:" + uuid + ";name=Bluetooth SPP Server";

    // open server url
    StreamConnectionNotifier streamConnNotifier =
        (StreamConnectionNotifier) Connector.open(connectionString);

    // Wait for client connection
    System.out.println("\nServer Started. Waiting for clients to connect...");
    while (isRunning) {
      connection = streamConnNotifier.acceptAndOpen();
      System.out.println("Connection opened");
      RemoteDevice dev = RemoteDevice.getRemoteDevice(connection);
      System.out.println("Remote device address: " + dev.getBluetoothAddress());
      System.out.println("Remote device name: " + dev.getFriendlyName(true));

      inStream = connection.openInputStream();
      outStream = connection.openOutputStream();

      if ((dev.getFriendlyName(true) == Config.pairedDevice) || true) {
        new Receiver().start();
        new Sender().start();
      }
    }
    streamConnNotifier.close();
  }