title: BluetoothServerSocket accept fails and throws an IOException
body: <p>I have a device which supports the OBEX Object Push Profile, this profile is based upon the Serial Port Profile. My guess is that I can use the Android Bluetooth Chat example for connecting this device to my Android Phone. But I ran into a problem, regarding the <code>socket.accept()</code> functionality in the android SDK. I try to accomplish to connect my phone with this device like this:</p>
  
  <pre><code>adapter = BluetoothAdapter.getDefaultAdapter(); 
  device = adapter.getRemoteDevice("00:1B:DC:0F:EC:7E");
  
  AcceptThread = new AcceptThread(true, adapter, device);
  AcceptThread.start(); 
  </code></pre>
  
  <p>The constructor in AcceptThread is coded like this:</p>
  
  <pre><code>public AcceptThread(boolean secure, BluetoothAdapter adapter, BluetoothDevice device) {
      BluetoothServerSocket tmp = null;
      this.adapter = adapter;
      this.device = device;
  
      // Create a new listening server socket
      try {
          tmp = adapter.listenUsingInsecureRfcommWithServiceRecord(device.getName(), UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"));
      } catch (Exception e) {
          Log.e(TAG, ".AcceptThread # listen() failed", e);
      } 
      mmServerSocket = tmp;
  }
  </code></pre>
  
  <p>The problem is when I try to do a <code>connect()</code> as I said before</p>
  
  <pre><code>public void run() {
      BluetoothSocket socket = null;
  
      // Listen to the server socket if we're not connected
      while (mState != STATE_CONNECTED) {
          try {
              // This is a blocking call and will only return on a
              // successful connection or an exception
              Log.d(TAG, "AcceptThread.run: accepting server socket connection");
  
              socket = mmServerSocket.accept(20000); 
  
              Log.d(TAG, ".AcceptThread.run # server socket connection accepted");
          } catch (Exception e) {
              Log.e(TAG, ".run # accept() failed: "+e);
              break;
          }
      }
  }
  </code></pre>
  
  <p>As you can see the ServerSocket accept every incomming connection for <code>20 seconds</code> or <code>20000 ms.</code> When the time is up, the app will throw an IOException like this</p>
  
  <pre><code>07-11 10:30:08.355: E/SIMPLECONNECT(1301): .run # accept() failed: java.io.IOException: Connection timed out
  </code></pre>
  
  <p>which tells me that my device couldnt connect to my android phone. The device doesnt have a connect button on the display, just a send functionalitywhich will send a file to my phone. I believe that this send functionality also do a connect in the background, but I am not sure. </p>
  
  <p>Can anybody pinpoint any solutions for me? I am running my app on a <code>Samsung Galaxy SIII</code> with <code>Android 4.0.4</code></p>