Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js Websocket消息接收检测失败_Node.js_Express_Websocket - Fatal编程技术网

Node.js Websocket消息接收检测失败

Node.js Websocket消息接收检测失败,node.js,express,websocket,Node.js,Express,Websocket,这里是ws-library。。 现在,我如何使用发送方法,例如我可以检测到消息发送失败?我已经试过回叫,试着接球。。也许我错过了什么 现在我正在做这件事。。它可以发送消息 BulletinSenderHelper.prototype.sendMessage = function(bulletin, device) { var message = JSON.stringify({ action: 'bulletin:add', data: bulletin

这里是ws-library。。

现在,我如何使用发送方法,例如我可以检测到消息发送失败?我已经试过回叫,试着接球。。也许我错过了什么

现在我正在做这件事。。它可以发送消息

BulletinSenderHelper.prototype.sendMessage = function(bulletin, device) {
    var message = JSON.stringify({
        action: 'bulletin:add',
        data: bulletin.data
    });

    if (device.is_active) {
        logger.debug('Sending message to %s', device.id);
        device.conn.send(message); // device.conn == ws . though i am checking it is active or not, sometimes it fails to send the message. i have to detect it.
    } else {
        logger.debug('Client %s is inactive, queuing bulletin', device.id);
        this.queueBulletin(device, bulletin);
    }
};

为send()实现回调没有帮助?device.conn.send(消息,函数ack(错误){logger.debug(“错误%s”,错误);//其他要做的事情…});//获得了未定义的错误消息总是成功和失败