简体   繁体   English

socket.io对象没有方法“发出”

[英]socket.io object has no method 'emit'

I am getting this error message 我收到此错误消息

TypeError: Object [object Object] has no method 'emit' TypeError:对象[object Object]没有方法'emit'

when trying to access a socket in helpQue , which is constructed with helpQue.push(socket) . 尝试访问helpQue的套接字时,该helpQue.push(socket)helpQue.push(socket)构造。

Both helpQue and cxsQue are arrays of sockets. 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);

I switched the code to 我将代码切换到

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);

it worked. 有效。 I assume there was something going on with splice , but can't figure out what. 我认为splice发生了什么事,但无法弄清楚是什么。 If anyone knows please let me know. 如果有人知道,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM