title: Write an outputstream after reading bluetooth socket android
body: <p>I want to write after reading from a device (via Bluetooth socket )
  The problem is that the while(true) finish when the socket is closed so I can't Write again.</p>
  
  <p>This is the code:</p>
  
  <pre><code>        try {
              // This will block until it succeeds in connecting to the device
              // through the bluetoothSocket or throws an exception
              bluetoothSocket.connect();
              try {
                  connectingThread.sleep(1000);
              } catch (InterruptedException e) {
                  e.printStackTrace();
              }
              outstream = bluetoothSocket.getOutputStream();
              outstream.write("P".getBytes());
              instream = bluetoothSocket.getInputStream();
              byte[] buffer = new byte[128];  // buffer store for the stream
              int bytes; // bytes returned from read()
              String readMessage = "";
  
               // Keep listening to the InputStream until an exception occurs
              while (true) {
                  try {
                      // Read from the InputStream
                      bytes = instream.read(buffer);
                      if(bytes!= -1){
                      // Send the obtained bytes to the UI activity
                      readMessage = new String(buffer, 0, bytes);
  
                      arrayList.add(readMessage);
                      biodyMsg = TextUtils.join("", arrayList);
                      }
  
                  } catch (Exception e) {
  
                      Log.d("Read Error", e.toString());
  
                  }finally {
                      outstream = bluetoothSocket.getOutputStream();
                      outstream.write("F".getBytes());
                  }
                  break;
              }
  
          } catch (IOException connectException) {
              connectException.printStackTrace();
              try {    
                  bluetoothSocket.close();
              } catch (IOException closeException) {
                  closeException.printStackTrace();
              }
          }
  </code></pre>
  
  <p><a href="http://i.stack.imgur.com/r0p9r.png" rel="nofollow">Logcat</a></p>
  
  <p>Can you help me </p>