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.
63 lines
1.7 KiB
63 lines
1.7 KiB
12 years ago
|
<!DOCTYPE html>
|
||
|
<meta charset="utf-8" />
|
||
|
<title>WebSocket Test</title>
|
||
|
<script language="javascript" type="text/javascript">
|
||
|
var myName = Math.random().toString(36).substring(7);
|
||
|
var websocket;
|
||
|
var myself = {
|
||
|
"name": myName,
|
||
|
"width": 0,
|
||
|
"height": 0
|
||
|
};
|
||
|
|
||
|
function init() {
|
||
|
document.getElementById("myName").innerHTML = myName;
|
||
|
show_size();
|
||
|
testWebSocket();
|
||
|
}
|
||
|
function testWebSocket() {
|
||
|
websocket = new WebSocket("ws://127.0.0.1:7681");
|
||
|
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) {
|
||
|
document.getElementById("status").innerHTML = "CONNECTED";
|
||
|
doSend();
|
||
|
}
|
||
|
function onMessage(evt) {
|
||
|
document.getElementById("people").innerHTML = evt.data;
|
||
|
setTimeout(function(){
|
||
|
doSend();
|
||
|
}, 1000);
|
||
|
}
|
||
|
function doSend(message) {
|
||
|
myself.name = myName;
|
||
|
myself.width = window.innerWidth;
|
||
|
myself.height = window.innerHeight;
|
||
|
|
||
|
websocket.send(JSON.stringify(myself));
|
||
|
}
|
||
|
function onError(evt) {
|
||
|
document.getElementById("status").innerHTML = 'ERROR: ' + evt.data;
|
||
|
}
|
||
|
function onClose(evt) {
|
||
|
document.getElementById("status").innerHTML = "DISCONNECTED";
|
||
|
}
|
||
|
|
||
|
function show_size(){
|
||
|
document.getElementById("reso").innerHTML = window.innerWidth + 'x' + window.innerHeight;
|
||
|
}
|
||
|
|
||
|
window.addEventListener("load", init, false);
|
||
|
window.addEventListener("resize", show_size, false);
|
||
|
</script>
|
||
|
|
||
|
<p>My name is: <span id="myName"></span>
|
||
|
<p>My resoltion is: <span id="reso"></span>
|
||
|
<p>Response of server: <span id="people"></span>
|
||
|
<p>Status: <span id="status">unknown</span>
|
||
|
|
||
|
</html>
|