n2o_proto.htm 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  4. <link href="synrc.css" type="text/css" rel="stylesheet">
  5. </head>
  6. <body>
  7. <div class="threecol">
  8. <div class="left">
  9. <div class="hints"></div>
  10. <div class="main">
  11. <h1><a name="chapter2">N2O Protocol</a></h1>
  12. <h2><a name="p1.1">JSON container</a></h2>
  13. <p>Each message from Web Socket channel to Client encoded as JSON object.
  14. <a href="https://github.com/synrc/n2o_scripts/blob/master/n2o/n2o.js">N2O.js</a>
  15. is used to decode WebSocket binary messages from JSON container.</p>
  16. <code>{ "eval": "ws.send("Send Back This String");",
  17. "data": [131,104,2,100,0,7,109,101,115,115,
  18. 97,103,101,107,0,5,72,101,108,108,111] }
  19. </code>
  20. <p>EVAL values evaluated immediately and DATA values passed
  21. to handle_web_socket(data) function if exists.</p>
  22. <code>function handle_web_socket(body) { console.log(body); } </code>
  23. <h2><a name="p1.1">BERT messages</a></h2>
  24. <p>Usually in DATA come <a href="http://bert-rpc.org">BERT</a> messages (Binary Erlang Term Format).
  25. <a href="https://github.com/synrc/n2o_scripts/blob/master/n2o/bert.js">BERT.js</a>
  26. is used to decode Game Protocol message.</p>
  27. <code>function handle_web_socket(body) {
  28. console.log(String(bert.decodebuf(body))); } </code>
  29. <code style="background-color:white;">E> Received: {message,"Hello"} </code>
  30. </div>
  31. <div class="contents">
  32. <iframe src="contents.htm" frameborder=0 width=340 height=2190></iframe>
  33. </div>
  34. </div>
  35. </body>
  36. </html>