I am testing HTML5 server sent events to see if I can use it in my project. I tried to follow the tutorial on http://www.html5rocks.com/en/tutorials/eventsource/basics and http://www.w3schools.com/html/html5_serversentevents.asp, but could not get it to work.
Here's my html (sse.html) and python cgi script (sse.py):
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript">
var source = new EventSource("/cgi-bin/sse.py");
source.onmessage = function(event) {
console.log(event.data);
};
</script>
</head>
<body>
Testing SSE!
</div>
</body>
</html>
sse.py as follows:
import sys
import datetime
import time
sys.stdout.write('Content-type: text/event-stream\r\n\r\n')
while True:
now = datetime.datetime.now()
sys.stdout.write('data: %s\r\n\r\n' % now)
sys.stdout.flush()
time.sleep(5)
I put 'sse.html' into 'c:\code\sse', and 'sse.py' into 'c:\code\sse\cgi-bin'. Then, I ran 'python -m CGIHTTPServer' to bring up the development web server.
When I connected to 'http://localhost:8000/sse.html', I didn't see the console logging the data received from the server. Instead, I saw a message saying that "Resource interpreted as Script but transferred with MIME type text/plain: "chrome-extension://hgimnogjllphhhkhlmebbmlgjoejdpjl/bar.js"."
Does anyone know what would be the problem?
Thanks!