@ -2,13 +2,13 @@
< 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;
var wsUri = "ws://127.0.0.1 :7681";
var people ;
var myName = Math.ra ndom().toString(36).substring(7) ;
function init() {
output = document.getElementById("output ");
n = 10 ;
people = document.getElementById("people ");
document.getElementById("myName").innerHTML = myName ;
testWebSocket();
}
function testWebSocket() {
@ -19,15 +19,14 @@
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.");
doSend(myName);
}
function onClose(evt) {
writeToScreen("DISCONNECTED");
}
function onMessage(evt) {
writeToScreen(evt.data);
setTimeout(function(){doSend(evt.data );}, 1000);
setTimeout(function(){doSend(myName );}, 1000);
}
function onError(evt) {
writeToScreen('< span style = "color: red;" > ERROR:< / span > ' + evt.data);
@ -36,11 +35,12 @@
websocket.send(message);
}
function writeToScreen(message) {
output .innerHTML = message;
people .innerHTML = message;
}
window.addEventListener("load", init, false);
< / script >
< div style = "font-family:Georgia, serif; text-align: center; font-size: 48pt;" id = "output" > < / div >
< p > My name is: < span id = "myName" > < / span >
< p > Response of server: < span id = "people" > < / span >
< / html >