2

我在带有蓝牙 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()
4

0 回答 0