What is Server-Side Code in HTML5

In this article I have describe about HTML5 SSC.
  • 2713

Server-Side Code Example

  • We need a server sending data updates ASP or PHP in this Example.
  • In this example above to work, we need a server capable of sending data updates (like PHP or ASP).
  • Syntax of SSE issimple, Set the "Content-Type" header to "text/event-stream".

Code in PHP (Server.php):

if ($_SERVER['HTTP_ACCEPT'] === 'text/event-stream')


    header('Content-Type: text/event-stream');  

    header('Cache-Control: no-cache');

    echo "data: This is the first event\n\n";


    $i = 5;

    while (--$i)



        $time = date('r');

        echo "data: The server time is: {$time}\n\n";





Code in ASP (VB) (Server.asp):


Response.Write("data: " & now())




Define the code

  • "Content-Type" header to "text/event-stream" is created.
  • Page should not cache in this server.asp.
  • "data" start to send the data and the output data back to the page.

Further Readings

You may also want to  read these related articles :

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

© 2020 DotNetHeaven. All rights reserved.