title: Getting java.io.IOException: read failed, socket might closed or timeout, read ret: -1 while printing via bluetooth printer
body: <p>Code is working fine for first time only, if i am trying to connect it again it is throwing this exception:</p>
  
  <blockquote>
    <p>read failed, socket might closed or timeout, read ret: -1</p>
  </blockquote>
  
  <p>This is my function for connecting to the bluetooth printer:</p>
  
  <pre><code>public boolean openBT(Context context) throws IOException {
      try {
          // Standard SerialPortService ID
          UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb");
          mmSocket = mmDevice.createRfcommSocketToServiceRecord(uuid);
          mBluetoothAdapter.cancelDiscovery();
  
          mmSocket.connect();
  
          mmOutputStream = new DataOutputStream(mmSocket.getOutputStream());
          mmInputStream = new DataInputStream(mmSocket.getInputStream());
  
  
      } catch (NullPointerException e) {
          e.printStackTrace();
          return false;
      } catch (Exception e) { 
           e.printStackTrace();
          return false;
  
      }
  
      return true;
  
  }
  </code></pre>