Websocket消息接收失败检测

时间:2016-04-02 12:29:36

标签: node.js express websocket

这是ws库.. https://github.com/websockets/ws/blob/master/lib/WebSocket.js

现在如何使用send方法,例如我可以检测到发送失败的消息?我试过回调并尝试捕捉......可能是我错过了什么..

现在我这样做..它可以发送消息..

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

0 个答案:

没有答案