我正在尝试在两个 python 文件之间建立套接字连接以进行测试。我的服务器应该将一些数据上传到正在监听的客户端。我试图通过创建一些虚拟客户端来测试它。客户端连接后,我得到
websocket._exceptions.WebSocketBadStatusException: Handshake status 404 NOT FOUND
不幸的是,我在网上找不到针对此错误的任何解决方案
import time
from threading import Thread
from flask import Flask
from flask_socketio import SocketIO
from flask_sockets import Sockets
from websocket import create_connection
app = Flask(__name__)
socketio = SocketIO(app)
sockets = Sockets(app)
@sockets.route('/socket_test')
def update_time(ws):
while not ws.closed:
ws.send('hello world')
time.sleep(1)
class Client(Thread):
def __init__(self):
super().__init__()
def run(self):
time.sleep(0.5)
ws = create_connection('ws://localhost:5000/socket_test')
while True:
ws.recv()
if __name__ == '__main__':
k = Client()
k.start()
socketio.run(app)
我希望客户端从服务器接收 hello world 消息