পৃষ্ঠাসমূহ

Search Your Article

CS

 

Welcome to GoogleDG – your one-stop destination for free learning resources, guides, and digital tools.

At GoogleDG, we believe that knowledge should be accessible to everyone. Our mission is to provide readers with valuable ebooks, tutorials, and tech-related content that makes learning easier, faster, and more enjoyable.

What We Offer:

  • 📘 Free & Helpful Ebooks – covering education, technology, self-development, and more.

  • 💻 Step-by-Step Tutorials – practical guides on digital tools, apps, and software.

  • 🌐 Tech Updates & Tips – simplified information to keep you informed in the fast-changing digital world.

  • 🎯 Learning Support – resources designed to support students, professionals, and lifelong learners.

    Latest world News 

     

Our Vision

To create a digital knowledge hub where anyone, from beginners to advanced learners, can find trustworthy resources and grow their skills.

Why Choose Us?

✔ Simple explanations of complex topics
✔ 100% free access to resources
✔ Regularly updated content
✔ A community that values knowledge sharing

We are continuously working to expand our content library and provide readers with the most useful and relevant digital learning materials.

📩 If you’d like to connect, share feedback, or suggest topics, feel free to reach us through the Contact page.

Pageviews

Thursday, February 23, 2017

HTML5 - Server Sent Events

Server Sent Events

It takes the updates from server and gives result on web browsers.Before take updates from server,browser would have to ask, if any updates were available in web servers.

Example

HTML5 code should be as follows
<html>
   <body>
   
      <h1> Server updates</h1>
      <div id="result"></div>
   
      <script>
         if(typeof(EventSource) !== "undefined") {
            var source = new EventSource("demo_sse.php");
         
            source.onmessage = function(event) {
               document.getElementById("result").innerHTML += event.data + "<br>";
            };
         }
      
         else {
            document.getElementById("result").innerHTML = "Sorry, your browser does not support ";
         }
      </script>
   </body>
</html>

demo_sse.php

Server Code should be in PHP,It looks like as follows
<?php
   header('Content-Type: text/event-stream');
   header('Cache-Control: no-cache');
   
   $time = date('r');
   echo "data: The server time is: {$time}\n\n";
   flush();
?>
The server time is: Thu, 23 Feb 2017 20:20:22 +0530
The server time is: Thu, 23 Feb 2017 20:20:30 +0530
The server time is: Thu, 23 Feb 2017 20:20:37 +0530
The server time is: Thu, 23 Feb 2017 20:20:44 +0530
The server time is: Thu, 23 Feb 2017 20:20:50 +0530
The server time is: Thu, 23 Feb 2017 20:20:56 +0530
The server time is: Thu, 23 Feb 2017 20:21:02 +0530
The server time is: Thu, 23 Feb 2017 20:21:10 +0530
The server time is: Thu, 23 Feb 2017 20:21:16 +0530
The server time is: Thu, 23 Feb 2017 20:21:22 +0530
The server time is: Thu, 23 Feb 2017 20:21:28 +0530
The server time is: Thu, 23 Feb 2017 20:21:34 +0530
The server time is: Thu, 23 Feb 2017 20:21:40 +0530
The server time is: Thu, 23 Feb 2017 20:21:45 +0530
The server time is: Thu, 23 Feb 2017 20:21:52 +0530
The server time is: Thu, 23 Feb 2017 20:21:57 +0530
The server time is: Thu, 23 Feb 2017 20:22:03 +0530
The server time is: Thu, 23 Feb 2017 20:22:09 +0530
The server time is: Thu, 23 Feb 2017 20:22:15 +0530
The server time is: Thu, 23 Feb 2017 20:22:20 +0530
The server time is: Thu, 23 Feb 2017 20:22:26 +0530 
You can get demo of Server Sent Events here

No comments:

Post a Comment