2

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

Exboy
  • 79
  • 7

1 Answers1

3

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.

jfriend00
  • 683,504
  • 96
  • 985
  • 979
  • 1
    Added more info on running two versions of socket.io on the server. – jfriend00 Feb 22 '23 at 03:57
  • about the first answer.. the server uses engine.io version 3... the question i asked was does socket.io client version 3.0 make use of engine.io version 3? – Exboy Feb 22 '23 at 07:52
  • 1
    @Exboy - See version info I added to the end of my answer. – jfriend00 Feb 22 '23 at 08:13
  • so that's a no is it?.. I see you said this ```Socket.io version 3.x and 4.x use engine.io v4``` .. the question I've been asking ever since is can a socket.io version 3.x make a successful connection to a server that uses engine.io v3 – Exboy Feb 22 '23 at 09:38
  • @Exboy - According to the socket.io doc, a socket.io 4.x server (running engine.io v4) will accept an incoming connection from a socket.io 3.x client (running engine.io v4). A socket.io v2.x client (using engine.io v3) will connect to a socket.io 4.x server if you set the right compatibility option that is linked in my answer. – jfriend00 Feb 22 '23 at 16:33
  • I understand what you say right here but my question is different still.. I've been asking if I sio client version 3 could make use of eio version 3 instead of its original version 4 – Exboy Feb 22 '23 at 16:36
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/252056/discussion-between-exboy-and-jfriend00). – Exboy Feb 22 '23 at 16:38
  • @Exboy - The doc does not cover the situation of a socket.io 3.x client (engine.io 4.x) connecting to a socket.io 1.x or 2.x server (engine.io 3.x). I would guess that would NOT work as compatibility layers are usually added to the server, not client, but you would have to try it yourself to prove that. If it's your client, you can roll the client back to an earlier version to match the server you're trying to communicate with. Or, if it's your server, you can advance the server to a newer version. – jfriend00 Feb 22 '23 at 16:38