| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title>Web Sockets echo test</title>
- <meta charset="UTF-8">
- <script src="include/mootools.js"></script>
- <script src="include/mootools-more.js"></script>
- <script>
- var cnt = 0;
- var s = null; var timer = null;
- function debug(str) {
- cell = $('debug');
- cell.innerHTML += str + "<br/>";
- }
- function send_data() {
- var entry = $('entry');
- debug(">> send: " + entry.value);
- s.send(entry.value + "\n");
- entry.value = ""; // Clear it
- return true;
- }
- window.onload = function() {
- debug(">> window.onload");
- var uri = new URI(window.location);
- var host = uri.getData("host");
- var port = uri.getData("port");
- if ((!host) || (!port)) {
- debug("must set host and port");
- return;
- }
- var location = "ws://" + host + ":" + port
- debug("connecting to " + location);
- s = new WebSocket(location);
- s.onmessage = function(e) {
- debug(">> onmessage");
- var out = $("out");
- out.innerHTML = out.innerHTML + e.data;
- };
- s.onopen = function(e) {
- debug(">> onopen");
- };
- s.onclose = function(e) {
- debug(">> onclose");
- if (timer) {
- timer = $clear(timer);
- }
- debug("<< onclose");
- }
- debug("<< window.onload");
- };
- </script>
- </head>
- <body>
- <h1>Web Sockets Interactive</h1>
- <fieldset>
- <h3>Server output:</h3>
- <pre>
- <div id="out"></div>
- </pre>
- </fieldset>
- <p>Enter something in the entry below to send to the server.</p>
- <fieldset>
- <p>Enter: <input id="entry" onkeypress="{if (event.keyCode==13) send_data()}" size="42"></p>
- <!-- <p>Enter: <input id="entry" onchange="send_data()" onkeypress="{if (event.keyCode==13) send_data()}" size="42"></p> -->
- </fieldset>
-
- <br><br>
- Debug:
- <div id="debug" style="width:600px;height:300px"></div>
- </body>
|