title: RFCOMM connection between two Android devices?
body: <p>I have two Android devices which I want to connect, using Bluetooth, and transfer data over an RFCOMM channel. I only one one device to receive data, while the other device sends it...</p>
  
  <p>Using this code, I am able to connect to the other device and begin listening to an RFCOMM channel:</p>
  
  <pre><code>Method m = device.getClass().getMethod("createRfcommSocket", new Class[] { int.class });
  socket = (BluetoothSocket) m.invoke(device, 2);
  socket.connect();
  
  class BasicThread implements Runnable{    
  
          public void run() {
              try {
                  InputStream stream = socket.getInputStream();
                  BufferedReader r = new BufferedReader(new InputStreamReader(stream));
                  while (true){
                      Log.d("myapp", "now listening...");
                      latestLine = r.readLine();
                      Log.d("myapp", latestLine);
                  }
              } catch (IOException e) {
  
              }
          } 
      }
  
      new Thread(new BasicThread()).run();
  </code></pre>
  
  <p>Using the other device, I have implemented a listening socket like this:</p>
  
  <pre><code>Method m = blue.getClass().getMethod("listenUsingRfcommOn", new Class[] { int.class });
  BluetoothServerSocket socket = (BluetoothServerSocket) m.invoke(blue, 2);
  
  BluetoothSocket sock = socket.accept();
  
  Log.d("myapp", "Connected...\n\n\n\n\n\n\n\n");
  
  OutputStream s = sock.getOutputStream();
  final PrintWriter out = new PrintWriter(s);
  </code></pre>
  
  <p>They both connect on RFCOMM channel 2, and both SEE eachother, however, the second device always remains blocked at the <code>BluetoothSocket sock = socket.accept();</code></p>
  
  <p>Any help?</p>