Tag: 防病毒

node.js中的SSE不会触发“message listener”,直到res.end()。 原因是在代码或

请咨询一下。 客户代码: var source = new EventSource('/notifications/stream'); source.addEventListener('open', function(e) { console.log('SSE connected') }, false); source.addEventListener('message', function(e) { alert('yes') console.log('SSE connected') }, false); 服务器代码 // set timeout as high as possible req.socket.setTimeout(Infinity); // send headers for event-stream connection // see spec for more information res.writeHead(200, { 'Content-Type': 'text/event-stream', 'Cache-Control': 'no-cache', 'Connection': 'keep-alive' }); res.write('\n'); setInterval(function(){ console.log('writing'); […]