与Pybluez librairy的OSError

时间:2017-04-07 11:34:26

标签: python bluetooth raspberry-pi pybluez

我想在带有蓝牙加密狗的笔记本电脑和Windows 7以及我的覆盆子pi 3之间进行蓝牙通信。

我在互联网上发现了一些使用Pybluez librairy的教程,但这对我不起作用。

在下面找到服务器部分的代码:

import bluetooth

Host = ""
port = 12

HostAddr = (Host, port)

def setupServer():
    server_socket=bluetooth.BluetoothSocket( bluetooth.RFCOMM )
    print("Socket Created.")
    server_socket.bind(HostAddr)
    server_socket.listen(1)
    print("Socket bind complete")

    client_sock, client_info = server_socket.accept()
    print("Accepted connection from " , client_info)

    try:
        while True:
            data = client_sock.recv(1024)
            if len(data) == 0: break
            print("received [%s]" %data)
    except IOError:
        pass

    print("Disconnected")

client_sock.close()
server_socket.close()
print("all done")

setupServer()

这是输出:

Socket Created.
Traceback (most recent call last):
  File "path_to_file\Server.py", line 33, in <module>
setupServer()
  File "path_to_file\Server.py", line 12, in setupServer
server_socket.bind(HostAddr)
  File "C:\Python34\lib\site-packages\bluetooth\msbt.py", line 60, in bind
bt.bind (self._sockfd, addr, port)
OSError

你知道为什么我有这个错误吗?

0 个答案:

没有答案