Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/212.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python android.bluetooth.BluetoothSocket无法连接_Python_Android_Sockets_Bluetooth - Fatal编程技术网

Python android.bluetooth.BluetoothSocket无法连接

Python android.bluetooth.BluetoothSocket无法连接,python,android,sockets,bluetooth,Python,Android,Sockets,Bluetooth,我尝试了其他评论中的所有建议,但都没有效果,我希望有人能帮助我。我已经为这个问题挣扎了三天了。我非常确定我的UUID是正确的,我知道清单中启用了蓝牙访问 我正在尝试将我的android应用程序连接到运行在Fedora中的python服务器。它断断续续地工作,现在一点也没有。我收到的android例外情况大致如下所示。。当btSocket.connect()时会引发这些错误;在下面附加的代码中执行 12-09 05:08:42.331: ERROR/BluetoothService(676): j

我尝试了其他评论中的所有建议,但都没有效果,我希望有人能帮助我。我已经为这个问题挣扎了三天了。我非常确定我的UUID是正确的,我知道清单中启用了蓝牙访问

我正在尝试将我的android应用程序连接到运行在Fedora中的python服务器。它断断续续地工作,现在一点也没有。我收到的android例外情况大致如下所示。。当btSocket.connect()时会引发这些错误;在下面附加的代码中执行

12-09 05:08:42.331: ERROR/BluetoothService(676): java.io.IOException: Service discovery failed

这是我的android bluetooth类,应该负责所有事情。当主应用程序类收到套接字已连接到的消息时,线程启动。我的蓝牙课程是基于

下面是我的python代码的关键部分。我对这段代码很有信心

# pybluez library
import bluetooth

server_socket = bluetooth.BluetoothSocket( bluetooth.RFCOMM )
client_sockets = []

server_socket.bind(("",bluetooth.PORT_ANY))
port = server_socket.getsockname()[1]
uuid = "00001101-0000-1000-8000-00805F9B34FB"

print "Listening for devices..."

# advertise service
server_socket.listen(1)
bluetooth.advertise_service( server_socket, "Validation Host",
    service_id = uuid,
    service_classes = [ uuid, bluetooth.SERIAL_PORT_CLASS ],
    profiles = [ bluetooth.SERIAL_PORT_PROFILE ],
)

# accept incoming connections
client_sock, client_info = server_socket.accept()
client_sockets.append(client_sock)
print "Accepted Connection from ", client_info

感谢您的关注。

您的代码总体上看起来不错,我假设您只是从一些示例中复制并粘贴它

一些Android手机(如HTC desire)中存在一个bug,导致方法device.createrFComSocketToServiceRecord失败。我建议采取以下办法:

1) 正在尝试使用提供的pythong脚本在两台linux计算机之间聊天 (你知道在哪里) 这样,您就可以验证Linux设置是否正常工作

2) 尝试启动从计算机到Android的连接(使用Android蓝牙聊天客户端python)请注意,默认的BluetoothChat demo只能在第一次尝试时接受连接

3) 尝试从Android手机连接到linux计算机,但使用以下代码手动指定RFCOMM通道号

// BUGBUG: Following code is not properly implemented on HTC DESIRE
// mSocket =                  device.createRfcommSocketToServiceRecord(UUID.fromString("6a462dc0-703a-4bf3-a80e-a473a6332c64"));
// WORKAROUND: Connecting directly to RFCOMM channel 1
Method m = device.getClass().getMethod("createRfcommSocket", new Class[] { int.class });
mSocket = (BluetoothSocket) m.invoke(device, Integer.valueOf(1)); // 1==RFCOMM channel code 
您需要使用以下命令了解您的RFCOMM通道号:

# sdptool browse local
如果这不起作用,请尝试“CreateSecurerCommSocket”而不是“CreateSecurerCommSocket”。
// BUGBUG: Following code is not properly implemented on HTC DESIRE
// mSocket =                  device.createRfcommSocketToServiceRecord(UUID.fromString("6a462dc0-703a-4bf3-a80e-a473a6332c64"));
// WORKAROUND: Connecting directly to RFCOMM channel 1
Method m = device.getClass().getMethod("createRfcommSocket", new Class[] { int.class });
mSocket = (BluetoothSocket) m.invoke(device, Integer.valueOf(1)); // 1==RFCOMM channel code 
# sdptool browse local