Search code examples
javascriptsocket.ioengine.io

Is there a way of making socket.io client version 3.0 make use of EIO=3 in javascript


The goal is to connect to a socket.io server which uses version 3 of Engine.IO transport protocol EIO=3... This kind of 2 questions in one due to uncertainty... The first is can socket.io client version 3.0 make use of EIO=3 instead of using EIO=4 which is it's basic setting and the second question is how can I handle all the events that get sent by the server without stating the particular event(the reason for this is because I might not know the name of the event or be expecting it at all).. thanks


Solution

  • In socket.io, engine.io is the underlying protocol module for socket.io and the EIO parameter in the URL literally is an abbreviation for "engine.io".

    A version 3 engine.io client only talks to a version 3 engine.io server and it is the EIO=3 or EIO=4 that communicates the engine.io version. So, I don't think a version 3.0 client can talk to a version 4.0 server. That's just how they do it. So, if you have a 4.0 server, you need a 4.0 client.

    It is probably possible for your server to run both a 3.0 and a 4.0 server and somehow direct the incoming client request to the right server with some sort of middleware that detects the EIO=x value. I've not tried it myself or seen it done, but it should be feasible with the right code.

    As for listening for all events without naming them, there's a socket.io FAQ here that says that socket.io does not have that feature built in, but there is a third party plug-in (using middleware) that makes it possible.

    FYI, this article discusses the breaking changes made in v4 of engine.io.

    And, here's some prior discussion on how to run multiple versions of socket.io on the server.


    • Socket.io version 0.9 and below uses engine.io v2
    • Socket.io version 1.x and 2.x use engine.io v3
    • Socket.io version 3.x and 4.x use engine.io v4

    Because the engine.io major version did not change going from socket.io 3.x to 4.x, a 4.x server can accept connections from either a 3.x or 4.x socket.io client and with a compatibility option a 4.x server will even accept connections from a v2 socket.io client. See https://socket.io/blog/socket-io-4-release/ for details.