3292c4a995
- wsproxy.py: creates a web sockets to TCP socket proxy. - interact.html: prints received Web Sockets data and has text box to send strings.
83 lines
2.3 KiB
HTML
83 lines
2.3 KiB
HTML
<!DOCTYPE html>
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<title>Web Sockets echo test</title>
|
|
<meta charset="UTF-8">
|
|
<script src="mootools.js"></script>
|
|
<script src="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>
|
|
|
|
|
|
|