Created
April 3, 2017 20:09
-
-
Save toddself/07d1e8b325a1141fd5e35197929cb67d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http') | |
http.createServer(function (req, res) { | |
res.writeHead(200, { | |
'Content-Type': 'text/event-stream', | |
'Cache-Control': 'no-cache', | |
'Connection': 'keep-alive' | |
}) | |
res.write('retry: 10000\n') | |
res.write('event: connecttime\n') | |
res.write('data: ' + (new Date()) + '\n\n') | |
res.write('data: ' + (new Date()) + '\n\n') | |
var interval = setInterval(function () { | |
res.write('data: ' + (new Date()) + '\n\n') | |
}, 1000) | |
req.connection.addListener('close', function () { | |
clearInterval(interval) | |
}, false) | |
}).listen(8080) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Blatantly stolen from https://github.com/yoshuawuyts/knowledge/blob/master/browser/sse.md