Node.js Websocket消息接收检测失败
这里是ws-library。。 现在,我如何使用发送方法,例如我可以检测到消息发送失败?我已经试过回叫,试着接球。。也许我错过了什么 现在我正在做这件事。。它可以发送消息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
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”,错误);//其他要做的事情…});//获得了未定义的错误消息总是成功和失败