title: Is it possible to establish a Bluetooth connection with a Java/Android client and Python server?
body: <p>I am trying to make a bluetooth connection with my Android client and a Python server. However, I am unable to do so since my Android client always fails to connect. Now I am wondering whether it is possible at all to use an Android Bluetooth socket and a python socket together. Is that possible?</p>
  
  <p>And if so, do you have suggestions what else I might try? In a nutshell, this is what I do:</p>
  
  <p><strong>My Android client:</strong></p>
  
  <p>I get a Bluetooth device like this:</p>
  
  <pre><code>BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().
      getRemoteDevice(deviceAddress);
  </code></pre>
  
  <p>Where <code>deviceAddress</code> is equal to the bluetooth MAC address of my laptops bluetooth adapter. Which is <code>E0:F8:47:3F:80:49</code></p>
  
  <p>Then I use that <code>device</code> to create a Socket:</p>
  
  <pre><code>BluetoothSocket socket = device.createRfcommSocketToServiceRecord(MY_UUID);
  </code></pre>
  
  <p>Where <code>MY_UUID</code> is this string: <code>00001101-0000-1000-8000-00805F9B34FB</code></p>
  
  <p>After that I just call connect:</p>
  
  <pre><code>socket.connect();
  </code></pre>
  
  <p>And that is where it fails to connect. Maybe it is because of server wihich looks like this:</p>
  
  <p><strong>My Python server:</strong></p>
  
  <pre><code>import bluetooth 
  
  hostMACAddress = 'E0:F8:47:3F:80:49' # The MAC address of a Bluetooth adapter  
  port = 3 
  backlog = 1
  size = 1024
  s = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
  s.bind((hostMACAddress, port))
  s.listen(backlog)
  try:
  client, clientInfo = s.accept()
  while 1:
      data = client.recv(size)
      if data:
          print(data)
          client.send(data) # Echo back to client
  except: 
      print("Closing socket")
      client.close()
      s.close()
  </code></pre>