I am working on a simple web app which is done with angular and cherrypy (prototyping at the moment). I am uploading two files, and then calling a external python program within cherrypy to process them, using subprocess (popen). I am able to do this so far. What I want to achieve is the output from the external program (which I catch via popen) passed on to the client. My issue is that, I am trying to setup server sent events on cherrypy and having no success.
Here is my cherrypy method I am exposing (an example one from web):
@cherrypy.expose
def getUpdate(self):
#Set the expected headers...
cherrypy.response.headers["Content-Type"] = "text/event-stream;charset=utf-8"
def content():
yield "Hello,"
yield "world"
return content()
And here is the javascript client code (I have CORS enabled and working):
var sseEvent = new EventSource('http://localhost:8090/getUpdate');
sseEvent.onmessage = function (event) {
console.log(event);
};
sseEvent.onopen = function (event) {
//console.log("I have started...");
};
I have looked at this question and in this blog. Yet, the onmessage event on the EventSource object is not firing, on calling the function from the server side. My understanding is that, you can call the function from the server side and it will catch the event from the browser. I am wrong or the setup is wrong?