Esempio n. 1
0
 public BluetoothClient() throws BluetoothStateException {
   LocalDevice localDev = LocalDevice.getLocalDevice();
   System.out.println("Local Bluetooth Name is " + localDev.getFriendlyName());
   localDev.setDiscoverable(DiscoveryAgent.GIAC);
   DiscoveryAgent discovery = localDev.getDiscoveryAgent();
   discovery.startInquiry(DiscoveryAgent.GIAC, this);
 }
Esempio n. 2
0
  public static void main(String[] args) throws IOException {
    System.out.println("Main.main");

    LocalDevice localDevice = LocalDevice.getLocalDevice();

    localDevice.setDiscoverable(DiscoveryAgent.GIAC); // Advertising the service

    String address = "742F6896BDD2"; // A500
    UUID device_UUID = new UUID(address, false);
    String url = "btspp://localhost:" + device_UUID + ";name=A500";
    StreamConnectionNotifier server = (StreamConnectionNotifier) Connector.open(url);

    System.out.println("wait until client connects");
    StreamConnection connection = server.acceptAndOpen(); // Wait until client connects
    // === At this point, two devices should be connected ===//
    System.out.println("connected");
    DataInputStream dis = connection.openDataInputStream();

    char c;
    while (true) {
      c = dis.readChar();
      if (c == 'x') break;
    }

    connection.close();

    System.out.println("Main.end");
  }