Throwing IOException when I try to close the BluetoothSocket
<p>I have a problem with the bluetooth socket, I'm getting an <code>IOException</code> telling me: <code>Socket Closed</code></p>

<p>The exception occurs here: </p>

<pre><code>} catch (IOException e) {
        try {
          inputStream.close(); 
          socket.close();
        } catch (IOException e1) {
             Log.e("CLOSE: ", e.getMessage());
        } 
        Log.e("IO FROM RUN: ", e.getMessage());
}
</code></pre>

<p>The relevant codesnippet:</p>

<pre><code>class AcceptThread extends Thread {
    /**
     * Tag that will appear in the log.
     */
    private final String ACCEPT_TAG = AcceptThread.class.getName();

    /**
     * The bluetooth server socket.
     */
    private final BluetoothServerSocket mServerSocket;

    public AcceptThread() {
        BluetoothServerSocket tmp = null;
        try {
            tmp = mBluetoothAdapter.listenUsingRfcommWithServiceRecord(
                    "Bluetooth Service", UUID.fromString(defaultUUID));
        } catch (IOException e) {
            e.printStackTrace();
        }
        mServerSocket = tmp;
    }

    public void run() {
        BluetoothSocket socket = null;
        while (true) {
            try {
                Log.i(ACCEPT_TAG, "Listening for a connection...");

                socket = mServerSocket.accept();
                Log.i(ACCEPT_TAG, "Connected to "
                        + socket.getRemoteDevice().getName());

            } catch (IOException e) {
                break;
            }
            // If a connection was accepted
            if (socket != null) {

                ReadInputThread inputThread = new ReadInputThread(socket); 
                inputThread.start();

            }
        }


    }

    /** Will cancel the listening socket, and cause the thread to finish */
    public void cancel() {
        try {
            mServerSocket.close();
        } catch (IOException e) {
        }
    }

    class ReadInputThread extends Thread {

        BluetoothSocket socket;
        InputStream inputStream;

        public ReadInputThread(BluetoothSocket socket) {
            InputStream tempIs = null;
            try {
                this.socket = socket;
                tempIs = socket.getInputStream();
            } catch (IOException e) {
                Log.e("IO: ", e.getMessage());
            }

            inputStream = tempIs;
        }

        public void run() {

            Log.i(TAG, "BEGIN ReadInputThread");
            final byte[] buffer = new byte[1024];
            int bytes;

            while (true) {

                try {
                    bytes = inputStream.read(buffer);
                    if(inputStream.available() &lt; 0) {
                        inputStream.close();
                        socket.close();
                    }

                    Log.i("BYTE COUNT: ", Integer.toString(bytes)); 
                    Log.i("BYTES: ", new String(buffer)); 

                } catch (IOException e) {
                    try {
                        inputStream.close(); 
                        socket.close();
                    } catch (IOException e1) {
                    Log.e("CLOSE: ", e.getMessage());
                    } 
                    Log.e("IO FROM RUN: ", e.getMessage());
                }
            }


        }
    }
</code></pre>

<p>Can anybody give me a hint on how to solve this issue? Thanks! </p>
