1
我正在使用python龙卷风框架为我写的游戏编写一个小型Web服务器。 ,该GET请求工作正常但是当我尝试创建一个WebSocket连接我得到这个错误在我的浏览器:Web Socket未连接到龙卷风服务器
这里是我的javascript代码:
var ws = new WebSocket("ws://localhost:8888/ws");
ws.onopen = function() {
ws.send("ping");
};
下面是代码对于python服务器:
class StateQueryHandler(tornado.websocket.WebSocketHandler):
def open(self):
state.players = state.players + 1
self.write(state.players)
print("socket opened")
。 。 。
application = tornado.web.Application([
(r"/ws", StateQueryHandler),#websocket endpoint
(r"/static/(.*)", tornado.web.StaticFileHandler, {"path": "../client"})
])
server = tornado.httpserver.HTTPServer(application)
server.listen(8888)
tornado.ioloop.PeriodicCallback(state.update, 250).start()
tornado.ioloop.IOLoop.instance().start()
谁能告诉我发生了什么问题吗?为了保持tcp连接的活跃,我需要在服务器端做额外的事情吗?