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.
40 lines
1.1 KiB
40 lines
1.1 KiB
12 years ago
|
<!DOCTYPE html>
|
||
|
<meta charset="utf-8" />
|
||
|
<title>WebSocket Test</title>
|
||
|
<script language="javascript" type="text/javascript">
|
||
|
var websocket;
|
||
|
var list_of_people;
|
||
|
|
||
|
function init() {
|
||
|
testWebSocket();
|
||
|
}
|
||
|
function testWebSocket() {
|
||
|
websocket = new WebSocket("ws://127.0.0.1:7681", "observer");
|
||
|
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";
|
||
|
// needs to be non-empty
|
||
|
websocket.send("a");
|
||
|
}
|
||
|
function onMessage(evt) {
|
||
|
list_of_people = JSON.parse(evt.data);
|
||
|
}
|
||
|
function onError(evt) {
|
||
|
document.getElementById("status").innerHTML = 'ERROR: ' + evt.data;
|
||
|
}
|
||
|
function onClose(evt) {
|
||
|
document.getElementById("status").innerHTML = "DISCONNECTED";
|
||
|
}
|
||
|
|
||
|
window.addEventListener("load", init, false);
|
||
|
</script>
|
||
|
|
||
|
<p>Response of server: <span id="people"></span>
|
||
|
<p>Status: <span id="status">unknown</span>
|
||
|
|
||
|
</html>
|