title: Xamarin bluetooth in Android connection fails
body: <p>I'm trying to establish a bluetoothconnection to another phoner. Later on, it'll be a board with a HC5 module, but for debugging I'm just using a phone. </p>
  
  <p>The problem is, that connect fails and throws an IO Exception: 
  " read failed, socket might closed or timeout, read ret: -1"</p>
  
  <p>A quick google-search shows a lot having this problem. The only way I can see it solved, is by using a method not public in the API </p>
  
  <pre><code>Method m = mmDevice.getClass().getMethod("createRfcommSocket", new Class[] {int.class});
  mmSocket = (BluetoothSocket) m.invoke(mmDevice, 1);
  </code></pre>
  
  <p>The problem just is, that <code>createRfcommSocket</code> has been removed, and the result from getMethod will be null. </p>
  
  <p>My code is from the example: <a href="https://github.com/xamarin/monodroid-samples/tree/master/BluetoothChat" rel="nofollow noreferrer">https://github.com/xamarin/monodroid-samples/tree/master/BluetoothChat</a> which for connecting is:</p>
  
  <pre><code>        public ConnectThread(BluetoothDevice device, BluetoothChatService service)
          {
              UUID MY_UUID = UUID.FromString("00001101-0000-1000-8000-00805f9b34fb");
              mmDevice = device;
              _service = service;
              BluetoothSocket tmp = null;
  
              // Get a BluetoothSocket for a connection with the
              // given BluetoothDevice
              try
              {
                  if ((int)Android.OS.Build.VERSION.SdkInt &gt;= 10) // Gingerbread 2.3.3 2.3.4
                      tmp = device.CreateInsecureRfcommSocketToServiceRecord(MY_UUID);
                  else
                      tmp = device.CreateRfcommSocketToServiceRecord(MY_UUID);
  
  
              }
              catch (Java.IO.IOException e)
              {
                  Log.Error(TAG, "create() failed", e);
              }
              mmSocket = tmp;
          }
  </code></pre>
  
  <p>Since the 'original hack' doesn't work, and I haven't found any other solution, I'm hoping somebody here knows how to fix this. </p>
  
  <p>Best regards!</p>