【发布时间】:2019-11-13 12:53:01
【问题描述】:
我一直在尝试在项目中使用 socket.io,但是,我的 io.on 不断被触发。 我无法理解为什么它在循环中。 正如其他答案所建议的那样,我已经交叉检查了这些版本,它们都是一样的。 任何帮助都会很棒。 这是它的代码 服务器:-
io.on('connection', async function(socket){
//These both lines are being called again and again
console.log("Test");
socket.emit('new_token');
});
这将是一个消费者:
this.socket.on('new_token', () => {
// console.log(data);
this.notifier.notify('warning','Embeded token has been updated. Reloading in 3 seconds. !');
setTimeout(()=>{
window.location.reload();
}, 3000);
});
【问题讨论】: