Using HTML5 Server-Sent Events in a web application

PHPPERLPythonJavascriptWeb Development

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>
raja
Published on 10-Apr-2018 16:39:40
Advertisements