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