Aller au contenu principal

Socket.IO 3.1.0

· 2 minutes de lecture
Damien Arrachequesne

Hello everyone!

We just published a new version of Socket.IO: 3.1.0

In order to ease the migration to Socket.IO v3, the v3 server is now able to communicate with v2 clients:

const io = require("socket.io")({
allowEIO3: true // false by default
});

This should make the migration easier for existing deployments:

  • first, update the servers with allowEIO3 set to true
const io = require("socket.io")({
allowEIO3: true // false by default
});

Note: If you are using the Redis adapter to broadcast packets between nodes, you must use socket.io-redis@5 with socket.io@2 and socket.io-redis@6 with socket.io@3. Please note that both versions are compatible, so you can update each server one by one (no big bang is needed).

  • then, update the clients

This step may actually take some time, as some clients may still have a v2 client in cache.

You can check the version of the connection with:

io.on("connection", (socket) => {
const version = socket.conn.protocol; // either 3 or 4
});

This matches the value of the EIO query parameter in the HTTP requests.

  • and finally, once every client was updated, set allowEIO3 to false (which is the default value)
const io = require("socket.io")({
allowEIO3: false
});

With allowEIO3 set to false, v2 clients will now receive an HTTP 400 error (Unsupported protocol version) when connecting.

The migration guide was updated accordingly.

Features​

Bug Fixes​