views:

7

answers:

1

I have a python script (in the CherryPy framework) that sends Event: and data: text as this Opera blog post describes to a client browser. The javascript that recieves the x-dom-event-stream content is almost identical to what they show in the blog post. However, the browser displays only the first event sent. Anyone know what I'm missing?

I tried a few older versions of Opera and found that it works in Opera 9.52 but not in any newer versions. What did they change?

Here is the python code:

class dumpData(object):
  def index(self):
    cherrypy.response.headers['Content-Type'] = "application/x-dom-event-stream"

    def yieldData():
      i = 0
      while 1:
        yield "Event: count\n"
        yield "data: "
        yield i
        yield "\n\n"
        i = i + 1
        time.sleep(3);

    return yieldData()

index._cp_config = {'response.stream': True}
index.exposed = True

And here is the javascript/html. Making a request to /data/ runs the python function above.

<head>
  <script>
    onload = function() { 
      document.getElementById("count").addEventListener("cout", cout, false);
    }
    function count(e) {
      document.getElementById("stream").firstChild.nodeValue = e.data;
    }
  </script>
  <event-source id="count" src="/data/">
</head>
<body>
  <div id="stream"></div>
</body>

Opening the direct /data/ url in Firefox saves the stream to a file. So I know the output is in the correct format and that the stream works at all.

+2  A: 

It's a bug. Sorry about that :-/

(For the record: CORE-28592 in Opera's unfortunately closed bug tracker.)

hallvors