小编use*_*395的帖子

android蓝牙连接错误(读取失败的套接字可能关闭或超时)

我想从Android设备中的应用程序连接到远程设备(配对).远程设备是HC-05模块.
我的代码是:

UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb"); //Standard SerialPortService ID

try {
    mSocket = MyDevice.createRfcommSocketToServiceRecord(uuid);
} catch (IOException e) {
    Toast.makeText(this, "S", Toast.LENGTH_SHORT).show();
}  

ba.cancelDiscovery();

try {
    mSocket.connect();
} catch (IOException e){
    Toast.makeText(this, e.getLocalizedMessage(), Toast.LENGTH_SHORT).show();

    Log.e("YOUR_APP_LOG_TAG1", "I got an error", e);
}

try {
    mOutputStream = mSocket.getOutputStream();
    mInputStream = mSocket.getInputStream();
} catch (IOException e) {
    Toast.makeText(this, "io", Toast.LENGTH_SHORT).show();
}
Run Code Online (Sandbox Code Playgroud)

但我在行mSocket.connect()中遇到错误.

错误:

读取失败的套接字可能会关闭或超时读取ret

请帮忙.

android bluetooth arduino

8
推荐指数
1
解决办法
8573
查看次数

同时运行两个函数

我有两个功能。我如何同时运行两个函数?我知道应该使用线程。我需要一个多线程示例。我正在使用 Visual Studio 2010

c++ visual-studio-2010

3
推荐指数
1
解决办法
7201
查看次数

标签 统计

android ×1

arduino ×1

bluetooth ×1

c++ ×1

visual-studio-2010 ×1