PageRenderTime 58ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 0ms

/data_push/index.cfm

https://github.com/andreacfm/websockets_example_apps
ColdFusion | 63 lines | 58 code | 5 blank | 0 comment | 3 complexity | c34b0a1555e77742e7fc8b0c2a4f8384 MD5 | raw file
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Railo Websockects Demo Apps - Data Push</title>
  5. <link href="assets/style.css" rel="stylesheet" type="text/css">
  6. </head>
  7. <body>
  8. <div id="main">
  9. <h1>Data Push</h1>
  10. <p>
  11. This examples shows how you can push data from your Railo app to clients connected via the WebSockects Gateway.<br/>
  12. We simulate a stock exchange widget that gets updated any 2 sec with fake data coming from our Railo server.<br/> The websocket gateway is nothing
  13. more than a regular Railo gateway. As any other gateway can be invoked using the the <b>sendGatewayMessage()</b> function.
  14. </p>
  15. <script src="https://gist.github.com/810167.js?file=sendGatewayMessage"></script>
  16. <p>
  17. When the websocket gateway receive a ping will push the <b>data.message</b> value to any connected client. Of course if you configured a listener this will be invoked
  18. before to send the message out. Btw is not the case of this example app.
  19. </p>
  20. <h2>About this example app</h2>
  21. <p>
  22. We need to simulate a service on the server that send out data for our clients. We do that with a thread that run for 2 min. The thread is very easy :
  23. </p>
  24. <script src="https://gist.github.com/810191.js?file=websocket%20data_push%20example%20-%20data.cfm"></script>
  25. <p>As you see the thread simply create a set of data and push them to the gateway. That's it.</p>
  26. <h2>Run the gateway</h2>
  27. <ul>
  28. <li>Go to your Railo Admin and create a WebSocket Gateway that listen on port <b>10126</b>. Call it <b>stocks</b></li>
  29. <li>Go to page <a href="data.cfm" target="_blank">data.cfm</a> to start the thread.</li>
  30. <li>Go to page <a href="stocks.cfm" target="_blank">stocks.cfm</a> and see your widget gets fresh data any 2 secs.</li>
  31. </ul>
  32. <p>
  33. When you run the stocks.cfm page a new websocket is opened and as soon as is registered will start to get data. Go to the same page with more browsers or just
  34. open another browser tab. Anytime a new client connects will start to receive data for Railo gateway.
  35. </p>
  36. <p>
  37. After 2 min the thread will be killed so you will need to reload <a href="data.cfm" target="_blank">data.cfm</a> to make it restart.
  38. </p>
  39. <h2>Important</h2>
  40. <p>Not all the browsers support websockets out of the box. This example does not implement any library that allows a failover to flash for browser that doeas not support
  41. websockets. You can use Chrome, Safari or Firefox4(in beta up to this time).
  42. </p>
  43. <h2>More about the Gateway</h2>
  44. <p>Find more info about the gateway in the <a href="http://wiki.getrailo.org/wiki/Extensions:WebSockets_Gateway" target="_blank">Railo wiki pages</a></p>
  45. <p>Clone the source from <a href="https://github.com/andreacfm/WebSocket-Gateway-Extension" target="_blank">Github</a></p>
  46. </div>
  47. </body>
  48. </html>