我使用Flask
和 Flask-SocketIO
Python 应用程序内部。
最近,当我启动应用程序时,我收到以下消息:
The client is using an unsupported version of the Socket.IO or Engine.IO protocols (further occurrences of this error will be logged with level INFO)
通过我的搜索,我得出this table在 Flask-SocketIO 的文档中,这表明我的系统存在版本不兼容问题。
我想知道我拥有哪个版本的 JavaScript Socket.IO。如何做到这一点?
系统详细信息
如果这不是很明显,那么我是 JavaScript 新手。
- 操作系统:macOS 版本 10.15.7
- JavaScript 版本:1.7
- 浏览器:Google Chrome 版本 87.0.4280.88
- Python版本:3.8.6
- 来自 Python 虚拟环境的包:
Flask 1.1.2
Flask-SocketIO 5.0.1
python-engineio 4.0.0
python-socketio 5.0.4
最佳答案
冲突可能是由于在客户端和服务器上使用不同的协议(protocol)修订版造成的。
The protocol defines the format of the packets exchanged between the client and the server. Both the client and the server must use the same revision in order to understand each other.
要确定客户端的修订号,
来自 HTML:
<script src="<your-path-to>socket.io.js"></script>
<script>
const socket = io('http://localhost');
const revisionNumber = socket.protocol;
</script>
或者来自 JavaScript:
const io = require('socket.io-client');
// or with import syntax
import { io } from 'socket.io-client';
const revisionNumber = io.protocol;
或者来自 Flask-SocketIO 源代码:
- 在文件
__init__.py
中搜索__version__
。该行将如下所示:
__version__ = '5.0.2dev'
- 使用该
__version__
值查找相应的 Socket.IO 协议(protocol)修订版:
+--------------+----------------+
| __version__ | protocol rev. |
+--------------+----------------+
| 4.x.x | 3, 4 |
+--------------+----------------+
| 5.x.x | 5 |
+--------------+----------------+
关于javascript - 如何获取JavaScript Socket.IO版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65636439/