我正在使用NodeJs v0.10.28,每次我尝试登录聊天时都会收到错误消息
TypeError: Object #<Socket> has no method 'set' at Socket.<anonymous>
如果我删除它的工作线但不能正常工作.
这段代码中的错误是什么
// get the name of the sender
socket.get('nickname', function (err, name) {
console.log('Chat message by ', name);
console.log('error ', err);
sender = name;
});
Run Code Online (Sandbox Code Playgroud)
和
socket.set('nickname', name, function () {
// this kind of emit will send to all! :D
io.sockets.emit('chat', {
msg : "Welcome, " + name + '!',
msgr : "Nickname"
});
});
Run Code Online (Sandbox Code Playgroud)
完整的代码