小编Fr3*_*d0m的帖子

"TypeError:这不是一个类型化的数组."Node.js中的WS.js

我在我的服务器文件中只有这个,并出现错误:

const WebSocket = require('ws');

const wss = new WebSocket.Server({ port: 9000 });

wss.broadcast = function broadcast(data) {
  wss.clients.forEach(function each(client) {
    if (client.readyState === WebSocket.OPEN) {
      client.send(data);
  }
});
};

wss.on('connection', function connection(ws) {
    ws.on('message', function incoming(data) {
        wss.broadcast(data);
    });
});
Run Code Online (Sandbox Code Playgroud)

终端显示此错误:

/home/mgmaip/server/node_modules/ws/lib/PerMessageDeflate.js:8
const TRAILER = Buffer.from([0x00, 0x00, 0xff, 0xff]);
                       ^

TypeError: this is not a typed array.
    at Function.from (native)
    at Object.<anonymous> (/home/mgmaip/server/node_modules/ws/lib/PerMessageDeflate.js:8:24)
    at Module._compile (module.js:397:26)
    at Object.Module._extensions..js (module.js:404:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at …
Run Code Online (Sandbox Code Playgroud)

javascript websocket node.js

5
推荐指数
1
解决办法
3365
查看次数

标签 统计

javascript ×1

node.js ×1

websocket ×1