server-sent-events

Setting time interval in HTML5 server sent events

北城以北 提交于 2019-11-27 15:14:20
问题 I want to send regular updates from server to client. For that I used server-sent event. I'm pasting the codes below: Client side Getting server updates <script> if(typeof(EventSource)!="undefined") { var source=new EventSource("demo_see.php"); source.onmessage=function(event) { document.getElementById("result").innerHTML=event.data + "<br>"; } } else { document.getElementById("result").innerHTML="Sorry, your browser does not support server-sent events..."; } </script> </body> </html> Server

HTML5 Server-Sent Events prototyping - ambiguous error and repeated polling?

别来无恙 提交于 2019-11-27 14:43:30
I'm trying to get to grips with Server-Side Events as they fit my requirements perfectly and seem like they should be simple to implement, however I can't get past a vague error and what looks like the connection repeatedly being closed and re-opened. Everything I have tried is based on this and other tutorials. The PHP is a single script: <?php header('Content-Type: text/event-stream'); header('Cache-Control: no-cache'); function sendMsg($id, $msg) { echo "id: $id" . PHP_EOL; echo "data: $msg" . PHP_EOL; echo PHP_EOL; ob_flush(); flush(); } $serverTime = time(); sendMsg($serverTime, 'server

SSE and Servlet 3.0

安稳与你 提交于 2019-11-27 13:02:40
问题 I have registered a typical SSE when page loads: Client: sseTest: function(){ var source = new EventSource('mySSE'); source.onopen = function(event){ console.log("eventsource opened!"); }; source.onmessage = function(event){ var data = event.data; console.log(data); document.getElementById('sse').innerHTML+=event.data + "<br />"; }; } My Javascript-Debugger says, that "eventsource opened!" was successfully. My Server Code is a Servlet 3.0: import java.io.IOException; import java.io

PHP Event Source keeps executing

不羁岁月 提交于 2019-11-27 08:10:05
问题 I started using push in HTML5 using the JavaScript EventSource object. I was totally happy with a working solution in PHP: $time = 0; while(true) { if(connection_status() != CONNECTION_NORMAL) { mysql_close() break; } $result = mysql_query("SELECT `id` FROM `table` WHERE UNIX_TIMESTAMP(`lastUpdate`) > '".$time."'"); while($row = mysql_fetch_array($result)) { echo "data:".$row["id"].PHP_EOL; echo PHP_EOL; ob_flush(); flush(); } $time = time(); sleep(1); } But suddenly my WebApp wasn't

H15 on Heroku SSE request

一个人想着一个人 提交于 2019-11-27 06:54:12
问题 I have a Node.js application on Heroku. I've recently switched a long query to use SSE (EventSource). While it works great and fast on my machine, I keep getting an Error H15 (Idle connection) on my GET request. The H15 description says I went over 55 seconds allowed per transaction. But my entire query doesn't take more than 4-5 seconds. Furthermore, after reading the description, I'm returning my first byte (just a number) immediately upon hitting the query, before it starts any heavy work

Server-sent events and php - what triggers events on the server?

可紊 提交于 2019-11-27 05:06:45
问题 All, HTML5 Rocks has a nice beginner tutorial on Server-sent Events (SSE): http://www.html5rocks.com/en/tutorials/eventsource/basics/ But, I don't understand an important concept - what triggers the event on the server that causes a message to be sent? In other words - in the HTML5 example - the server simply sends a timestamp once : <?php header('Content-Type: text/event-stream'); header('Cache-Control: no-cache'); // recommended to prevent caching of event data. function sendMsg($id, $msg)

server sent events (eventsource) with standard asp.net mvc causing error

我们两清 提交于 2019-11-27 04:56:43
I am trying my hand at server-sent events, but I cannot get it to work within an MVC project (not WebAPI). I haven't found any good samples online. This is the server-side code I tried (including several failed attempts from various posts): Function GetRows() as ActionResult Dim ret = New HttpResponseMessage ' ret.Content.w ' Return ret Response.ContentType = "text/event-stream" Response.Write("data: " & "aaaa") Dim flag = False If flag Then For i = 0 To 100 Response.Write("data: " & i) Next End If Response.Flush() 'Return Content("Abv") 'Return Content(("data: {0}\n\n" & DateTime.Now.ToString

Is Comet obsolete now with Server-Sent Events and WebSocket? [closed]

ぃ、小莉子 提交于 2019-11-27 01:08:10
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 6 years ago . or do Server-Sent Events and WebSocket replace Comet techniques? 回答1: Comet is a set of technology principles/communication patterns that are typically implemented using HTTP long-poll. It enables a server to send data to the browser on demand (i.e. server push). Current comet

JavaScript EventSource SSE not firing in browser

ぐ巨炮叔叔 提交于 2019-11-26 23:01:26
问题 I have been developing a nodejs server to provide server-side-events for a new website I am developing in HTML5. When I telnet to the server it works correctly, sending me the required HTTP response headers followed by a stream of events that i am presently generating every 2 or 3 seconds just to prove it works. I have tried the latest version of FireFox, Chrome and Opera and they create the EventSource object and connect to the nodejs server OK but none of the browsers generate any of the

Server-Sent Events vs Polling

最后都变了- 提交于 2019-11-26 19:14:17
问题 Is there a big difference (in terms of performance, browser implementation availability, server load etc) between HTML5 SSEs and straight up Ajax polling? From the server side, it seems like an EventSource is just hitting the specified page every ~3 seconds or so (though I understand the timing is flexible). Granted, it's simpler to set up on the client side than setting up a timer and having it $.get every so often, but is there anything else? Does it send fewer headers, or do some other