简体   繁体   English

bluetoothsocket.connect()在第二次运行时引发异常

[英]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.

相关问题 BluetoothSocket.connect()抛出IOException - BluetoothSocket.connect() throws IOException BluetoothSocket.connect()引发异常“读取失败” - BluetoothSocket.connect() throwing exception “read failed” BluetoothSocket.connect 不会抛出异常,但我没有连接 - BluetoothSocket.connect doesn't throw an exception, but I'm not connected Android BluetoothSocket :: connect()引发异常 - Android BluetoothSocket::connect() throws an exception Android BluetoothSocket.connect()引发IOExceptions“连接被拒绝”和“服务发现失败” - Android BluetoothSocket.connect() throws IOExceptions “Connection Refused” and “Service discovery failed” Android AlertDialog 直到 bluetoothsocket.connect() 之后才会显示 - Android AlertDialog won't show until after bluetoothsocket.connect() 我从来没有从BluetoothSocket.connect()中脱身 - I never get out from BluetoothSocket.connect() 带有Android 9的Samsung S9上BluetoothSocket.connect()失败 - BluetoothSocket.connect() fails on Samsung S9 with Android 9 为什么在Toast.makeText()。show()之前调用BluetoothSocket.connect()? - Why is BluetoothSocket.connect() called before Toast.makeText().show()? Android:BluetoothSocket连接抛出IOException - Android: BluetoothSocket connect throws IOException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM