ad_page_contract { Sample page for emulating streaming HTML via SSE (server side events). In this example, the same page is used as the event sink (where the events are displayed) and as an event source (when called with event=true). @author Gustaf Neumann } { {event:boolean false} } set title "Sample HTML streaming page (SSE)" set context $title if {$event} { # # We are called by the event handler from JavaScript # # # Trivial sse writer # proc sse_write {msg} { # SSE needs handling of new-lines in data field; here we send # two messages in this case. In other cases, maybe coding # newline as literally \n and decoding it on the client might # be approproate. ns_write [string cat "data:" [join [split $msg \n] "\ndata:"] "\n\n"] } # # set up SSE return headers and fire a few events # ns_set update [ns_conn outputheaders] Cache-Control no-cache ns_headers 200 text/event-stream foreach i {1 2 3 4} { set HTML "