【问题标题】:socket.io object has no method 'emit'socket.io 对象没有方法 'emit'
【发布时间】:2013-09-29 19:00:58
【问题描述】:

我收到此错误消息

TypeError: Object [object Object] 没有方法'emit'

尝试访问helpQue 中的套接字时,该套接字由helpQue.push(socket) 构造。

helpQuecxsQue 都是套接字数组。

setInterval(function() {
    if(helpQue.length > 0 && cxsQue.length > 0) {
        var id = makeid(),
            helpee = helpQue.splice(0, 1);

            helpee.emit('server-output', 'Test'); //ERROR here
    }
}, 1000);

【问题讨论】:

    标签: javascript node.js socket.io


    【解决方案1】:

    我将代码切换到

    setInterval(function() {
        if(helpQue.length > 0 && cxsQue.length > 0) {
            var id = makeid(),
                helpee = helpQue[0];
                helpQue.splice(0, 1);
    
                helpee.emit('server-output', 'Test');
        }
    }, 1000);
    

    成功了。我认为splice 发生了什么事,但不知道是什么。如果有人知道,请告诉我。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-22
      • 1970-01-01
      • 1970-01-01
      • 2014-08-04
      • 2015-03-16
      • 2023-03-08
      • 2012-11-13
      • 1970-01-01
      相关资源
      最近更新 更多