Search code examples
javascriptsocket.ioflask-socketio

How to get JavaScript Socket.IO version?


I use Flask and Flask-SocketIO inside of a Python application.

Recently, when I start up the app, I am given this message:

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)

From my searching, I come to this table in Flask-SocketIOs' docs, which suggests I have version incompatibilities in my system.

I would like to figure out which version of JavaScript Socket.IO I have. How can this be done?


System Details

If it's not obvious, I am new to JavaScript.

  • OS: macOS version 10.15.7
  • JavaScript version: 1.7
  • Browser: Google Chrome version 87.0.4280.88
  • Python version: 3.8.6
  • Packages from Python virtual environment:
Flask                                     1.1.2
Flask-SocketIO                            5.0.1
python-engineio                           4.0.0
python-socketio                           5.0.4

Solution

  • The conflict is probably from using different protocol revisions on the client and the server.

    From socket.io Client API:

    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.

    To determine the revision number of the client,

    From HTML:

    <script src="<your-path-to>socket.io.js"></script>
    <script>
      const socket = io('http://localhost');
    
      const revisionNumber = socket.protocol;
    </script>
    

    Or from JavaScript:

    const io = require('socket.io-client');
    // or with import syntax
    import { io } from 'socket.io-client';
    
    const revisionNumber = io.protocol;
    

    Or from the Flask-SocketIO source code:

    1. search for __version__ in the file __init__.py. The line will look like this:
    __version__ = '5.0.2dev'
    
    1. Using that __version__ value, look up the corresponding Socket.IO protocol revision:
    +--------------+----------------+
    | __version__  |  protocol rev. |
    +--------------+----------------+
    |    4.x.x     |     3, 4       |
    +--------------+----------------+
    |    5.x.x     |     5          |
    +--------------+----------------+