[英]bluetoothsocket.connect() throws exception in the second run
I created an Android app to connect to Arduino via bluetooth serial adapter, when I run the app it works fine the first time, after that the bluetoothsocket.connect() throws an exception, the code as follows:- socket connection: 我创建了一个Android应用程序以通过蓝牙串行适配器连接到Arduino,当我运行该应用程序时它第一次运行良好,之后bluetoothsocket.connect()引发异常,代码如下:-套接字连接:
mmSocket = mmDevice.createRfcommSocketToServiceRecord(uuid);
mBluetoothAdapter.cancelDiscovery();
mmSocket.connect();
// send data
mmSocket.close();
I don't know where is the problem 我不知道问题出在哪里
Problem solved, the problem was bluetoothsocket.close(); 问题解决了,问题是bluetoothsocket.close();。 I should not call this function 我不应该调用这个功能
仅在发送完所有数据且不再需要发送时才应关闭套接字,如果需要发送更多数据,请在重新连接之前重新配置套接字
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.