Skip to content

Instantly share code, notes, and snippets.

@toddself
Created April 3, 2017 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toddself/07d1e8b325a1141fd5e35197929cb67d to your computer and use it in GitHub Desktop.
Save toddself/07d1e8b325a1141fd5e35197929cb67d to your computer and use it in GitHub Desktop.
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)
@toddself
Copy link
Author

toddself commented Apr 3, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment