0

When we start this thread and it's called socket.connect() after that it came into catch and under catch i caught exception:

java.io.IOException: read failed, socket might closed or timeout, read ret: -1

What i used in the code.

 private class ConnectThread extends Thread {
    private  BluetoothSocket mmSocket;
    private final BluetoothDevice device;

    public ConnectThread(BluetoothDevice device) {
        // Use a temporary object that is later assigned to mmSocket,
        // because mmSocket is final
        BluetoothSocket tmp = null;
        this.device = device;
    }
        // Get a BluetoothSocket to connect with the given BluetoothDevice
       /* try {
            // MY_UUID is the app's UUID string, also used by the server code
            //UUID MY_UUID = UUID.randomUUID();
            tmp = device.createRfcommSocketToServiceRecord(uuid);
        } catch (IOException e) { }
        mmSocket = tmp;
    }*/

    public void run() {
        // Cancel discovery because it will slow down the connection
        mBluetoothAdapter.cancelDiscovery();

        try {
            BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(mac);
            final UUID SERIAL_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
            mmSocket = device.createRfcommSocketToServiceRecord(SERIAL_UUID);
            mmSocket.connect();
            OutputStream out = mmSocket.getOutputStream();
            InputStream in = mmSocket.getInputStream();
            Log.e("TAG" , ""+out);
            // Connect the device through the socket. This will block
            // until it succeeds or throws an exception
           // mmSocket.connect();
        } catch (IOException connectException) {
            // Unable to connect; close the socket and get out
            try {
                mmSocket.close();
            } catch (IOException closeException) { }
            return;
        }

        // Do work to manage the connection (in a separate thread)
        //manageConnectedSocket(mmSocket);
        new ConnectedThread(mmSocket).start();
    }

    /** Will cancel an in-progress connection, and close the socket */
    public void cancel() {
        try {
            mmSocket.close();
        } catch (IOException e) { }
    }
}
}

Now i don't know what i need to do.my mobile version is 5.0.1 but still i am getting same error i don't know why? Please any body help me out. thanks in advance.

diiN__________
  • 7,393
  • 6
  • 42
  • 69
user6615010
  • 122
  • 1
  • 12

0 Answers0