l2cap(113,'无路由主持人')

时间:2018-02-08 08:57:56

标签: python bluetooth raspberry-pi l2cap

我在蓝牙l2cap协议的rapsberry pi零中使用以下代码。我的客户端代码总是给我同样的错误

错误:

Traceback (most recent call last):
File "l2cap-client.py", line 11, in <module>
sock.connect((bd_addr, port))
File "<string>", line 5, in connect
bluetooth.btcommon.BluetoothError: (113, 'No route to host')

服务器代码:

import bluetooth
server_sock=bluetooth.BluetoothSocket( bluetooth.L2CAP )
port = 0x1001
server_sock.bind(("00:1B:DC:06:C1:AD",port))
server_sock.listen(1)
print(server_sock.getsockname())
client_sock,address = server_sock.accept()
print "Accepted connection from ",address
data = client_sock.recv(1024)
print "received [%s]" % data
client_sock.close()
server_sock.close()

客户代码:

import bluetooth
sock=bluetooth.BluetoothSocket(bluetooth.L2CAP)
bd_addr = "00:1B:DC:06:C1:AD"
port = 0X1001
#print(sock.getsockname())
sock.connect((bd_addr, port))
print(sock.getsockname())
sock.send("hello!!")
sock.close()

0 个答案:

没有答案