Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: is there any way to detect the used engine.io version? #35

Closed
Benedicht opened this issue Nov 10, 2020 · 11 comments
Closed

Question: is there any way to detect the used engine.io version? #35

Benedicht opened this issue Nov 10, 2020 · 11 comments
Labels

Comments

@Benedicht
Copy link

I have a c# implementation that should work with both v3 and v4. Because v4 has a few breaking changes, i can't implement them in a backward compatible way and different code must be executed based on the version of the server.

@Benedicht
Copy link
Author

A future proof solution would be if the handshake data would contain an additional version field. If it's missing than it's most probably a server using v3 otherwise its value is the version that i (and maybe other too) could use.

@darrachequesne
Copy link
Member

You should be able to detect the version of the Engine.IO server based on the format of the handshake packet:

// v3
96:0{"sid":"lv_VI97HAXpY6yYWAAAC","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":5000}
// v4
0{"sid":"lv_VI97HAXpY6yYWAAAC","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":5000}

Details:

@Benedicht
Copy link
Author

Thanks, that could work. Any advice for a websocket only session?

@darrachequesne
Copy link
Member

The first WebSocket frame sent by the server will contain the handshake packet, so you should be able to make the same distinction as above.

Screenshot from 2020-11-12 15-04-51

@Benedicht
Copy link
Author

Benedicht commented Nov 12, 2020

AFAIK it's the same for v3 and v4.

These are received from different versions:

0{"sid":"iEDbJrPFWsgeDYk-AAAB","upgrades":[],"pingInterval":25000,"pingTimeout":5000}
0{"sid":"nR4WsvYPR1J8XrSvAAAA","upgrades":[],"pingInterval":25000,"pingTimeout":5000}

The documentation also looks like the same (i couldn't find any differences at least) for v3 and v4:

@darrachequesne
Copy link
Member

Arf, you are right.

For a WebSocket-only session, I think the only difference is the encoding of a binary packet. The packet is prefixed with "4" in v3, whereas it is sent as is in v4.

@Benedicht
Copy link
Author

Yep, but that's hard to use to decide whether it's v3 or v4, because "4" can be part of the binary data too.

@Benedicht
Copy link
Author

@darrachequesne Any chance to include something in the handshake payload that would indicate the version of the protocol?

@darrachequesne
Copy link
Member

We could check the value of the EIO query parameter on the server-side, and return a HTTP 400 if the query param is provided but does not match the value of the server. What do you think?

@Benedicht
Copy link
Author

Hey, sorry for the late reply!

My only real objection is that it would add additional round-trips, but otherwise it seems good.

darrachequesne added a commit to socketio/engine.io that referenced this issue Jan 14, 2021
In order to ease the migration to Socket.IO v3, the Engine.IO server
can now communicate with v3.x clients.

```js
const eioServer = require("engine.io")(httpServer, {
  allowEIO3: true // false by default
});
```

If `allowEIO3` is false, the v3.x clients will now receive an HTTP 400
response ("Unsupported protocol version").

Note: the code of the v3 parser has been imported from [1] and
browser-related dependencies were removed.

[1]: https://github.com/socketio/engine.io-parser/tree/2.2.1

Related:

- socketio/engine.io-protocol#35
- socketio/socket.io-protocol#21
@darrachequesne
Copy link
Member

The server now supports v3 and v4 clients: socketio/engine.io@663d326 (included in engine.io@4.1.0 & socket.io@3.1.0).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants