我有Windows控制台应用程序(用C#编写),需要通过蓝牙从Android手机(运行Java应用程序)接收字符串 . Windows控制台应用程序使用32feet.Net库来处理蓝牙 .

这是从Android手机发送字符串的Java代码(为简洁起见,省略了重要细节):

BluetoothDevice targetDevice = getDeveice();
 BluetoothSocket socket = targetDevice.createRfcommSocketToServiceRecord(getUuid()); 
 socket.connect();
 OutputStream outputStream = socket.getOutputStream();
 outputStream.write("MyString".getBytes());

这是接收数据的C#代码:

string lgphone = "00:00:00:00:00:00"; // The MAC address of my phone, lets assume we know it
BluetoothAddress addr = BluetoothAddress.Parse(lgphone);
var btEndpoint = new BluetoothEndPoint(addr, new Guid("0000111f-0000-1000-8000-00805f9b34fb"));
var btClient = new BluetoothClient();
btClient.Connect(btEndpoint);
Stream peerStream = btClient.GetStream();
byte[] buf = new byte[1000];
int readLen = peerStream.Read(buf, 0, buf.Length);

BluetoothClient 已成功连接 . 但 peerStream 没有任何数据:(如果需要,我可以提供更多细节 .

一般方法是否正确?你能建议可能出错的吗?