You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.3 KiB
47 lines
1.3 KiB
12 years ago
|
<!DOCTYPE html>
|
||
|
<meta charset="utf-8" />
|
||
|
<title>WebSocket Test</title>
|
||
|
<script language="javascript" type="text/javascript">
|
||
|
var wsUri = "ws://vadovas-studios.com:7681";
|
||
|
var output;
|
||
|
var n;
|
||
|
|
||
|
function init() {
|
||
|
output = document.getElementById("output");
|
||
|
n = 10;
|
||
|
testWebSocket();
|
||
|
}
|
||
|
function testWebSocket() {
|
||
|
websocket = new WebSocket(wsUri);
|
||
|
websocket.onopen = function (evt) {onOpen(evt)};
|
||
|
websocket.onclose = function (evt) {onClose(evt)};
|
||
|
websocket.onmessage = function (evt) {onMessage(evt)};
|
||
|
websocket.onerror = function (evt) {onError(evt)};
|
||
|
}
|
||
|
function onOpen(evt) {
|
||
|
writeToScreen("CONNECTED");
|
||
|
doSend("In JavaScript, I rewrite every function so that it can end as soon as possible. You want the browser back in control so it can make your DOM changes.");
|
||
|
}
|
||
|
function onClose(evt) {
|
||
|
writeToScreen("DISCONNECTED");
|
||
|
}
|
||
|
function onMessage(evt) {
|
||
|
writeToScreen(evt.data);
|
||
|
setTimeout(function(){doSend(evt.data);}, 1000);
|
||
|
}
|
||
|
function onError(evt) {
|
||
|
writeToScreen('<span style="color: red;">ERROR:</span> ' + evt.data);
|
||
|
}
|
||
|
function doSend(message) {
|
||
|
websocket.send(message);
|
||
|
}
|
||
|
function writeToScreen(message) {
|
||
|
output.innerHTML = message;
|
||
|
}
|
||
|
window.addEventListener("load", init, false);
|
||
|
</script>
|
||
|
|
||
|
<div style="font-family:Georgia, serif; text-align: center; font-size: 48pt;"id="output"></div>
|
||
|
|
||
|
</html>
|