Piper Push Cache Documentation Download Samples Contact  

Hello SSE

A very simple example of how to use Piper Push Cache with Server Send Events.

1. Create a page (hello.html)
	      
<html>
  <body>
    <p id="status"> ... </p>
    <p id="message"> ... waiting ... </p>

    <script type="text/javascript">
      var src = new EventSource('sse?filter=*');
      src.onopen = function() {
          document.getElementById('status').textContent = 'connected';
      }
      src.onerror = function() {
          document.getElementById('status').textContent = 'not connected';
      }
      function doSet(e) {
          document.getElementById("message").textContent = e.data;
      }
      src.addEventListener('set', doSet, false);
      src.onmessage = function(e) {
      }
    </script>
  </body>
</html>
	    
2. Start Piper
	      
$> bin/piper -page.dir=samples/hello_sse
	    
3. Open page at http://localhost:7660/hello.html
	      
$>open samples/hello_sse/hello.html
	    
4. Create a JSON document (hello.json)
	      
"Hello World"
	    
5. Push the hello.json to Piper (watch the page)
	      
$> curl -T hello.json http://localhost:7661/say