简体   繁体   English

Socket.io v3 不支持的协议版本错误

[英]Socket.io v3 Unsupported protocol version error

I'm stuck with the newer version of socket.io.我坚持使用较新版本的 socket.io。 Everything was fine but when I wanted to upgrade to socket.io, everything just broke, and currently on the client, I'm getting a 400 HTTP status code with the following JSON response - {"code":5,"message":"Unsupported protocol version"}一切都很好,但是当我想升级到 socket.io 时,一切都坏了,目前在客户端上,我得到一个 400 HTTP 状态代码,带有以下 Z0ECD11C1D7A287401D148A23BBD75A2F 响应{"code":5,"message":"Unsupported protocol version"}

Serer-side config -服务器端配置 -

const io = require("socket.io")(server, {
    cors: {
      origin: config.clientURL,
      methods: ["GET", "POST"],
      credentials: true,
    },
  });

Client-side config -客户端配置 -

const socket = io(backendURL, {
  withCredentials: true,
});

I've tried very many things and redeployed many times but the error didn't go away.我已经尝试了很多事情并重新部署了很多次,但错误并没有 go 消失。

For reference, I've these github repos -作为参考,我有这些 github repos -

Client in react.js - GitHub repo react.js中的客户端 - GitHub repo

Server in nodeJs and socket.io.js - GitHub repo nodeJssocket.io.js中的服务器 - GitHub repo

Looks like there may be a mismatch between versions of your socket.io-client and socket.io server.看起来您的 socket.io-client 和 socket.io 服务器的版本之间可能存在不匹配。

First, update the servers with allowEIO3 set to true (added in socket.io@3.1.0)首先,更新服务器,将 allowEIO3 设置为 true(在 socket.io@3.1.0 中添加)

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

After you've upgraded the socket.io-client (latest right now is 3.1.1), you can set it back, or remove it since default is false升级 socket.io-client(现在最新的是 3.1.1)后,您可以将其设置回来,或将其删除,因为默认值为 false

 const io = require("socket.io")({ allowEIO3: false });

I install old version by我安装旧版本

npx create-nuxt-app@2.15.0

It will install nuxt with express.js in one project.它将在一个项目中安装带有 express.js 的 nuxt。 Then update npm packages by commands:然后通过命令更新 npm 包:

npx npm-check-updates -u
npm i

And socket.io goes well between nuxt and socket.io on server并且 socket.io 在服务器上的 nuxt 和 socket.io 之间运行良好

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM