Using HTML5 Server-Sent Events in a web application


To use Server-Sent Events in a web application, you would need to add an <eventsource> element to the document.

The src attribute of the <eventsource> element should point to an URL that should provide a persistent HTTP connection that sends a data stream containing the events.

The URL would point to a PHP, PERL or any Python script that would take care of sending event data consistently.

Example

Here is an example showing application that would expect server time.

<!DOCTYPE HTML>
<html>
   <head>
      <script>
         /* Define event handling logic here */
      </script>
   </head>

   <body>
      <div id = "sse">
         <eventsource src = "/cgi-bin/ticker.cgi" />
      </div>
      <div id = "ticker">
         <TIME>
      </div>
   </body>
</html>

Updated on: 20-Dec-2019

148 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements