]>
git.proxmox.com Git - ceph.git/blob - 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">
5 <script type='text/javascript'
language=
"javascript">
10 function webSockKeepAlive() {
12 connection.send('ping'); // Send the message 'ping' to the server
13 setTimeout("webSockKeepAlive()", 10000);
18 connection = new WebSocket("ws://127.0.0.1/MyWebSock");
20 connection.onopen = function () {
21 var send = "init " + Math.round(Math.random()*4294967294+1);
22 console.log('Client: ' + send);
23 connection.send(send);
28 connection.onerror = function (error) {
31 console.log('WebSocket error: ' + error);
32 alert("WebSocket error");
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);
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>