PageRenderTime 29ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/js/lib/Socket.IO-node/support/socket.io-client/lib/vendor/web-socket-js/sample.html

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
HTML | 75 lines | 57 code | 14 blank | 4 comment | 0 complexity | 4a0d5a0cf5dbc2eb3cca3c3f2c8774d3 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. <!--
  2. Lincense: Public Domain
  3. -->
  4. <html><head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6. <title>Sample of web_socket.js</title>
  7. <!-- Include these three JS files: -->
  8. <script type="text/javascript" src="swfobject.js"></script>
  9. <script type="text/javascript" src="web_socket.js"></script>
  10. <script type="text/javascript">
  11. // Set URL of your WebSocketMain.swf here:
  12. WEB_SOCKET_SWF_LOCATION = "WebSocketMain.swf";
  13. // Set this to dump debug message from Flash to console.log:
  14. WEB_SOCKET_DEBUG = true;
  15. // Everything below is the same as using standard WebSocket.
  16. var ws;
  17. function init() {
  18. // Connect to Web Socket.
  19. // Change host/port here to your own Web Socket server.
  20. ws = new WebSocket("ws://localhost:10081/");
  21. // Set event handlers.
  22. ws.onopen = function() {
  23. output("onopen");
  24. };
  25. ws.onmessage = function(e) {
  26. // e.data contains received string.
  27. output("onmessage: " + e.data);
  28. };
  29. ws.onclose = function() {
  30. output("onclose");
  31. };
  32. ws.onerror = function() {
  33. output("onerror");
  34. };
  35. }
  36. function onSubmit() {
  37. var input = document.getElementById("input");
  38. // You can send message to the Web Socket using ws.send.
  39. ws.send(input.value);
  40. output("send: " + input.value);
  41. input.value = "";
  42. input.focus();
  43. }
  44. function onCloseClick() {
  45. ws.close();
  46. }
  47. function output(str) {
  48. var log = document.getElementById("log");
  49. var escaped = str.replace(/&/, "&amp;").replace(/</, "&lt;").
  50. replace(/>/, "&gt;").replace(/"/, "&quot;"); // "
  51. log.innerHTML = escaped + "<br>" + log.innerHTML;
  52. }
  53. </script>
  54. </head><body onload="init();">
  55. <form onsubmit="onSubmit(); return false;">
  56. <input type="text" id="input">
  57. <input type="submit" value="Send">
  58. <button onclick="onCloseClick(); return false;">close</button>
  59. </form>
  60. <div id="log"></div>
  61. </body></html>