Piper Push Cache Documentation Download Samples Contact  

Hello World

A very simple example of how to use Piper Push Cache.

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

    <script type="text/javascript">
      var sock;
      var url = "ws://" + document.URL.split('/')[2]
      if (typeof MozWebSocket != "undefined") {
          sock = new MozWebSocket(url, "piper-protocol");
      } else {
          sock = new WebSocket(url, "piper-protocol");
      }
      sock.onopen = function() {
          sock.send("subscribe *");
      }
      sock.onmessage = function(msg) {
          document.getElementById("message").textContent = msg.data;
      }
    </script>
  </body>
</html>
	    
2. Start Piper
	      
$> bin/piper -page.dir=samples/hello_world
	    
3. Open page at http://localhost:7660/hello.html
	      
$>open samples/hello_world/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
	    
6. Try GET too
	      
$> curl http://localhost:7661/say