ws_ssl.html 1.47 KB
<html>
<head>
  <title>Websocket Proxy SSL Test</title>
  <meta charset="utf-8">
  <script>
  window.onload = function() {
    var protocols = ['ws://', 'wss://'];
    var websocketServers = ['ws1', 'ws2'];
    //protocols = ['wss://'];
    //websocketServers = ['ws1']

    var createWebsocketConnection = function(proto, server) {
      var conn = new WebSocket(proto + server);

      var div = document.createElement('div');
      var h2 = document.createElement('h2');
      h2.innerHTML = 'Connection to ' + proto + server;
      document.body.appendChild(h2);
      document.body.appendChild(div);

      conn.onmessage = function(ev) {
        var el = document.createElement('div');
        el.innerHTML = 'websocket message: ' + ev.data;
        div.appendChild(el);
        // Keep only last 5 messages in the list
        while (div.childNodes.length > 5) div.removeChild(div.firstChild);
      };

      // Send some string to the websocket connection periodically.
      // websocket server much echo it back.
      window.setInterval(function() { conn.send(Math.random()); }, 1000);
    };

    for (var i = 0; i < protocols.length; i++) {
      for (var j = 0; j < websocketServers.length; j++) {
        createWebsocketConnection(protocols[i], websocketServers[j]);
      }
    }
  };
  </script>
  <style>
    body > div {
      border: 1px solid #ccc; background: #f0f0f0; padding: 0 1em;
      margin: 0 2em; min-height: 4em; max-width: 40em;
    }
  </style>
</head>
<body>
</body>
</html>