3

When I try to connect first time, and server side device is in range - everything OK!

But, if device is unreachable (service discovery failed) my BT save that SDP record and don't want to connect anymore. I really think it's pretty stupid to cache this, it's look like "Oh we don't found this UUID on this Device. It's never exists in a whole world let's remember this forever".

Only if I change UUID or address it try again. But I can't close old and open new UUID listen port any time when device not found by client side.

How I can tell him "Clear this stupid record" or something like this.

PS:I need API10 that why I use "bConnected" instead isConnected();

Client code:

public void fire(View view) {
    final BluetoothAdapter BA = BluetoothAdapter.getDefaultAdapter();
    final String sUuid = "SuperHidenUuid";
    final UUID uuid = UUID.nameUUIDFromBytes(sUuid.getBytes());

    Thread t = new Thread(new Runnable() {
        @Override
        public void run() {
            OutputStream sOut;
            InputStream sIn;
            BluetoothSocket sConnection;
            BA.cancelDiscovery(); //shotgun debuging

            BluetoothDevice BD = BA.getRemoteDevice(sVictimBsid);
            try {
                sConnection = BD.createInsecureRfcommSocketToServiceRecord(uuid);
            } catch (IOException e) {
                return;
            }

            boolean bConnected = false;
            try {
                sConnection.connect();
                bConnected = true;
            } catch (IOException e) {
                e.printStackTrace();
            }

            try {
                if (bConnected) {
                    sIn = sConnection.getInputStream();
                    sOut = sConnection.getOutputStream();
                    sOut.write((sVictimPass + "\n").getBytes());
                    BufferedReader reader = new BufferedReader(new InputStreamReader(sIn));

// here I send and receive some data

                    sIn.close(); //shotgun debuging
                    sOut.close(); //shotgun debuging
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

            try {
                Thread.sleep(1000); //shotgun debuging
                sConnection.close();
                BA.cancelDiscovery(); //shotgun debuging
            } catch (IOException e) {
                e.printStackTrace();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    });

    t.start();
}
Alexey Kurilov
  • 438
  • 4
  • 10

0 Answers0