python - 服务器在 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'])
解决方案
推荐阅读
- matplotlib - 为什么 Matplotlib 中更高的 DPI 会给你更粗略的特征?
- php - Swig Php 和 enable_dl
- php - 输入错误的 url 时重定向到 404 页面
- spring-boot - Springboot从不同的url登录
- java - 当我的 android App 收到 firebase 消息通知时,然后关闭
- php - 如何通过 AJAX 将帖子发送到 PHP 并加载特定的 div
- java - 无法发送 Android 消息应用程序的推送通知?
- python - 使用掩码中的列表过滤数据框中的日期
- python - 在数据框中滚动 10 分钟的最近值
- c++ - 二叉搜索树中的删除操作