Slide 30
Slide 30 text
Node.js, part 2
function sendSSE(req, res) {
res.writeHead(200, {
'Content-Type': 'text/event-stream',
'Cache-Control': 'no-cache',
'Connection': 'keep-alive'
});
setInterval(function() {
constructSSE(res, ‘time’, (new Date()).toLocaleTimeString());
}, 5000);
}
function constructSSE(res, event, data) {
res.write('event: ' + event + '\n');
res.write("data: " + data + '\n\n');
}