osError:尝试以一种其访问权限python禁止的方式访问套接字

时间:2020-10-15 14:15:40

标签: python-3.x sockets pybluez

我正在尝试使用python脚本创建Bluetooth通信,但无法正常工作。 我的系统环境是(win-10(64位)),我正在使用python(3.8.3),python模块-pyBluez-win10创建此脚本。

这是我的服务器脚本:

import bluetooth

server_sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM )
print(server_sock)
print("Server socket created..")
port = 1
server_sock.bind(("",port))
print("socket bind successfully..")
server_sock.listen(1)
print("waiting for connection..")

client_sock,address = server_sock.accept()
print(client_sock)
print(address)
print ("Accepted connection from ",address)
data = client_sock.recv(1024)
print ("received [%s]" % data)
client_sock.close()
server_sock.close()

和我的客户端脚本一样令人沮丧。

import bluetooth

bd_addr = "C0:14:3D:D0:7F:10"

port = 1

sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM )
print("client socket created")
sock.connect((bd_addr, port))
sock.send("hello i am client!!")
sock.close()

但是当我尝试运行服务器脚本时,showm错误如下:

Socket crated successfully.
Traceback (most recent call last):
  File "server.py", line 19, in <module>
  File "bluetooth\msbt.py", line 72, in bind
OSError: An attempt was made to access a socket in a way forbidden by its access permissions.

有人知道如何解决此问题吗?

提前谢谢。

0 个答案:

没有答案