我做错了吗?当我运行node client.js
时。我收到此错误消息:
/web/ws/node_modules/socket.io/node_modules/engine.io/lib/server.js:358
var listeners = server.listeners('request').slice(0);
^
TypeError: Object http://localhost:8080 has no method 'listeners'
at Server.attach (/web/ws/node_modules/socket.io/node_modules/engine.io/lib/server.js:358:26)
at Function.attach (/web/ws/node_modules/socket.io/node_modules/engine.io/lib/engine.io.js:124:10)
at Server.listen.Server.attach (/web/ws/node_modules/socket.io/lib/index.js:226:21)
at new Server (/web/ws/node_modules/socket.io/lib/index.js:51:17)
at Server (/web/ws/node_modules/socket.io/lib/index.js:39:41)
at Object.<anonymous> (/web/ws/client.js:2:14)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
这是我的代码:
var io = require('socket.io');
var socket = io('ws://localhost:8080');
socket.on('connect', function () {
socket.send('hi');
socket.on('message', function (msg) {
// my msg
});
});
请提出建议。我在做错的地方?
答案 0 :(得分:4)