Javascript 类型错误:对象#<;接收器>;没有方法';在';

Javascript 类型错误:对象#<;接收器>;没有方法';在';,javascript,node.js,Javascript,Node.js,我正在尝试在节点上执行脚本,并出现以下错误: socket.io版本可能有问题? 代码将鼠标坐标发送到服务器,服务器将鼠标坐标发送到客户端。 非常感谢您的帮助,谢谢 pi@webserver~/cursores$sudo node server.js /home/pi/cursores/node_modules/websocket.io/lib/protocols/hybi-16.js:39 .on('text', function (packet) { ^ TypeError

我正在尝试在节点上执行脚本,并出现以下错误: socket.io版本可能有问题? 代码将鼠标坐标发送到服务器,服务器将鼠标坐标发送到客户端。 非常感谢您的帮助,谢谢

pi@webserver~/cursores$sudo node server.js

/home/pi/cursores/node_modules/websocket.io/lib/protocols/hybi-16.js:39
    .on('text', function (packet) {
     ^
TypeError: Object #<Receiver> has no method 'on'
    at new WebSocket (/home/pi/cursores/node_modules/websocket.io/lib/protocols/hybi-16.js:39:6)
    at Server.createClient (/home/pi/cursores/node_modules/websocket.io/lib/server.js:88:10)
    at Server.handleUpgrade (/home/pi/cursores/node_modules/websocket.io/lib/server.js:60:21)
    at HTTPServer.<anonymous> (/home/pi/cursores/node_modules/websocket.io/lib/websocket.io.js:92:8)
    at HTTPServer.emit (events.js:106:17)
    at Socket.socket.ondata (http.js:1990:14)
    at TCP.onread (net.js:527:27)

handlers socket.on()中的作用域在运行时可用,而不是在脚本编写时可用。 可能是函数
广播
未在处理程序中显示。 您可能需要在调用它之前声明它。 您可能需要强制它具有全局范围。 另见

我更新了代码的简化版本,抛出了相同的错误,这里没有范围函数。
var express = require('express');
var wsio = require('websocket.io');
var app = express.createServer();
var ws = wsio.attach(app);
app.use(express.static('public'));
ws.on('connection',function(socket) {
        console.log("Connection detected");
}); 
app.listen(3000);
console.log("Listening on port 3000");