我希望获得帮助,谢谢!
我试图同时运行Flask服务器和套接字服务器,这给了我以下错误:
OSError: [WinError 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted.
程序立即失败。我试图在绑定之前添加此行,套接字服务器会运行,但烧瓶服务器不会。
server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
我附上了代码,谢谢!
app = Flask(__name__)
IP = "127.0.0.1"
PORT = 2000
ADRESS = (IP,PORT)
# open socket with client
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind(ADRESS)
server_socket.listen(1)
global client_socket
client_socket, address = server_socket.accept()
print(str(address)+ ' coonected')
app.run(host='127.0.0.1',debug=True)