/js/lib/Socket.IO-node/support/socket.io-client/lib/vendor/web-socket-js/sample.html
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
- <!--
- Lincense: Public Domain
- -->
- <html><head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <title>Sample of web_socket.js</title>
-
- <!-- Include these three JS files: -->
- <script type="text/javascript" src="swfobject.js"></script>
- <script type="text/javascript" src="web_socket.js"></script>
- <script type="text/javascript">
-
- // Set URL of your WebSocketMain.swf here:
- WEB_SOCKET_SWF_LOCATION = "WebSocketMain.swf";
- // Set this to dump debug message from Flash to console.log:
- WEB_SOCKET_DEBUG = true;
-
- // Everything below is the same as using standard WebSocket.
-
- var ws;
-
- function init() {
- // Connect to Web Socket.
- // Change host/port here to your own Web Socket server.
- ws = new WebSocket("ws://localhost:10081/");
- // Set event handlers.
- ws.onopen = function() {
- output("onopen");
- };
- ws.onmessage = function(e) {
- // e.data contains received string.
- output("onmessage: " + e.data);
- };
- ws.onclose = function() {
- output("onclose");
- };
- ws.onerror = function() {
- output("onerror");
- };
- }
-
- function onSubmit() {
- var input = document.getElementById("input");
- // You can send message to the Web Socket using ws.send.
- ws.send(input.value);
- output("send: " + input.value);
- input.value = "";
- input.focus();
- }
-
- function onCloseClick() {
- ws.close();
- }
-
- function output(str) {
- var log = document.getElementById("log");
- var escaped = str.replace(/&/, "&").replace(/</, "<").
- replace(/>/, ">").replace(/"/, """); // "
- log.innerHTML = escaped + "<br>" + log.innerHTML;
- }
- </script>
- </head><body onload="init();">
- <form onsubmit="onSubmit(); return false;">
- <input type="text" id="input">
- <input type="submit" value="Send">
- <button onclick="onCloseClick(); return false;">close</button>
- </form>
- <div id="log"></div>
- </body></html>