]> git.proxmox.com Git - ceph.git/blob - ceph/src/civetweb/examples/_obsolete/websocket/websock.htm
buildsys: switch source download to quincy
[ceph.git] / ceph / src / civetweb / examples / _obsolete / websocket / websock.htm
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2 <html>
3 <head>
4 <title>Test</title>
5 <script type='text/javascript' language="javascript">
6 <!--
7 var connection;
8 var keepAlive = false;
9
10 function webSockKeepAlive() {
11 if (keepAlive) {
12 connection.send('ping'); // Send the message 'ping' to the server
13 setTimeout("webSockKeepAlive()", 10000);
14 }
15 }
16
17 function load() {
18 connection = new WebSocket("ws://127.0.0.1/MyWebSock");
19
20 connection.onopen = function () {
21 var send = "init " + Math.round(Math.random()*4294967294+1);
22 console.log('Client: ' + send);
23 connection.send(send);
24 keepAlive = true;
25 webSockKeepAlive();
26 };
27
28 connection.onerror = function (error) {
29 keepAlive = false;
30 connection.close();
31 console.log('WebSocket error: ' + error);
32 alert("WebSocket error");
33 };
34
35 connection.onmessage = function (e) {
36 console.log('Server: ' + e.data);
37 if (e.data.substring(0,5) == "title") {window.document.title = e.data.substring(6);}
38 else if (e.data.substring(0,3) == "msg") {
39 var msgStr = document.getElementById('msg');
40 msgStr.innerHTML = msgStr.innerHTML + e.data.substring(4);
41 }
42 };
43 }
44 //-->
45 </script>
46
47 </head>
48 <body onload="load()">
49 <input type="button" onclick="connection.send('msg A');" value="A"></button>
50 <input type="button" onclick="connection.send('msg B');" value="B"></button>
51 <input type="button" onclick="connection.send('msg C');" value="C"></button>
52 <input type="button" onclick="connection.send('msg D');" value="D"></button>
53 <b id="msg"></b>
54 </body>
55 </html>