File: page.thtml

package info (click to toggle)
libaws 20.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 16,656 kB
  • sloc: ada: 95,505; python: 2,270; ansic: 1,017; makefile: 829; xml: 235; javascript: 202; java: 112; sh: 106
file content (53 lines) | stat: -rw-r--r-- 1,269 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<html>
  <head>
    <title>Web Socket Demo</title>

    @@INCLUDE@@ ../../web_elements/javascripts/aws.tjs

    <script type="text/javascript">

      var ws;

      function updateP(id, message) {
        var a = document.getElementById(id);
        a.innerHTML = a.innerHTML + "<br>" + message;
      }

      function newMessage() {
        ws.send('A message sent after 5 seconds');
      }

      function startWS() {
          var server = window.location.host;
          var protocol = window.location.protocol;
          updateP('server', 'Server is ' + server);

          ws = AWS.WebSocket.open('ws' + protocol.substring (4) + '//' + server
                                  + '/echo', 'data', 'status');
          if (ws != false)
             updateP('status', "Your browser supports webSocket.");

          setTimeout (newMessage, 2000);
      };
    </script>
  </head>

  <body>
    <p>This is the main page, bellow is a simple websocket counter</p>
    <p>Click <button onclick="startWS()" value="Here">Here</button> to start</p>

    <p id="server"></p>

    <h3>Data</h3>
    <p id="data"></p>

    <h3>From user</h3>
    <p id="from_user"></p>

    <h3>Echo</h3>
    <p id="echo"></p>

    <h3>Status</h3>
    <p id="status"></p>
  </body>
</html>