title: Specific Android Bluetooth Server issue
body: <p>I have a very particular Android Bluetooth issue:</p>
  
  <p>I have a device (with almost no documentation) that acts as a Bluetooth Client and tries to connect (after pairing) to a Bluetooth Server that listens using the UUID "1234". I have tested in advance using a python script, that the device works and that it connects to the server. The relevant code from the script is:</p>
  
  <pre><code>import bluetooth
  
  uuid = "1234"
  
  pc = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
  
  pc.bind(("", bluetooth.PORT_ANY))
  pc.listen(1)
  
  port = pc.getsockname()[1]
  print 'Active RFCOMM port: ', port, '\r\n'
  
  bluetooth.advertise_service( pc, "Server",
     service_id = uuid,
     service_classes = [ uuid, bluetooth.SERIAL_PORT_CLASS ],
     profiles = [ bluetooth.SERIAL_PORT_PROFILE ] 
  )
  
  print 'Waiting for connection...\r\n'
  address = pc.accept()
  print 'Accepting connection from: ', address, '\r\n'
  </code></pre>
  
  <p>I am trying to create a similar server on Android using a BluetoothServerSocket. I have converted the 16-bit UUID ("1234"), according to this <a href="https://farwestab.wordpress.com/2011/02/05/some-tips-on-android-and-bluetooth/" rel="nofollow">article</a>, into "00001234-0000-1000-8000-00805F9B34FB". I have tested with a python script that the server is valid and that I can connect to it using the specified UUID. The code used is pretty standard, as it can be found in many examples across the internet:</p>
  
  <pre><code>@Override
  public void run() {
      BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
  
      Timber.i("Start Server");
      try {
          final BluetoothServerSocket bluetoothServer = adapter.listenUsingRfcommWithServiceRecord("Server", mUUID);
          Timber.i("Server Started: " + mUUID.toString());
  
          BluetoothSocket socket = bluetoothServer.accept();
          Timber.i("Socket initiated: " + socket.getRemoteDevice().getName());
  
          bluetoothServer.close();
      } catch (IOException e) {
          Timber.e("Error starting server: " + e.getMessage());
      }
  }
  </code></pre>
  
  <p>I have tried with both <code>listenUsingRfcommWithServiceRecord</code> and <code>listenUsingInsecureRfcommWithServiceRecord</code>. I have made sure the phone and the device are paired and that the phone is discoverable. I have tried with different phones with different OS versions (2.3.7, 4.0.3, 4.4.2, 5.1.0), as I thought that the change of the Bluetooth stack in Android 4.2 was the issue. Nothing seems to make the device to connect to my phone. I can also provide a hci dump from my Nexus 5 captured when the device was trying to connect, but I wasn't able to identify the issue.</p>
  
  <p>Any help would be appreciated.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>This is the python code used to verify the Android Bluetooth Server:</p>
  
  <pre><code>import sys
  import bluetooth
  
  uuid = "1234"
  service_matches = bluetooth.find_service( uuid = uuid )
  
  if len(service_matches) == 0:
      print "couldn't find the service"
      sys.exit(0)
  
  first_match = service_matches[0]
  port = first_match["port"]
  name = first_match["name"]
  host = first_match["host"]
  
  print "connecting to \"%s\" on %s" % (name, host)
  
  sock = bluetooth.BluetoothSocket( bluetooth.RFCOMM )
  sock.connect((host, port))
  sock.send("Test")
  sock.close()
  </code></pre>
  
  <p>Needless to say that it worked without any issues.</p>