我正在尝试在两个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)
我希望客户端从服务器接收世界问候消息