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
<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>