首页 > 解决方案 > 服务器在 vscode 上工作正常,但在 cmd 中不行

问题描述

我使用带有烧瓶的两台服务器编写了一个实时聊天应用程序。它们应该分别在端口 5000 和 80 上运行,并且这些端口上的客户端连接到这些服务器并可以相互聊天。结构应该是这样的。我使用 socketIO 在具有相同端口的客户端和服务器之间进行通信,我使用 python requests lib 在两个服务器之间进行通信。当我在两个 vscode 窗口上运行两个实例时,该程序运行良好,但是一旦我使用命令“flask run”运行服务器,服务器就会在第一次尝试在服务器之间进行通信时卡住。错误信息是这样的:“raise ChunkedEncodingError(e) requests.exceptions.ChunkedEncodingError: ("Connection broken: ConnectionResetError(10054, '一个现有的连接被远程主机强行关闭', None,

这是两个服务器之间发生第一次通信的视图:

@app.route('/search', methods=['POST'])
def search():
    global home
    global target
    target['port']=request.form.get('port')
    payload={'message':'connection_request','port':home["port"]}
    r=requests.post(f'http://127.0.0.1:{target["port"]}/connection',data=payload)
    stringifiesJson=r.json()
    target['name']=stringifiesJson['name']
    #target['port']=stringifiesJson['port']
    #header=f"the user {r1['name']} is register in port {r1['port']}"
    return render_template('chatbox.html', 
        name=home['name'],targetUser=stringifiesJson['name'],targetPort=stringifiesJson['port'])

标签: pythonflaskpython-requestsflask-socketiopython-socketio

解决方案


推荐阅读