summaryrefslogtreecommitdiffstats
path: root/simple/simple-http/src/test/java/org/simpleframework/http/socket/WebSocketChatRoom.html
blob: 1443c6918cf9319c9122d86399643f601e12cb4e (plain)
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
<html>
    <head>
        <title>WebSocket Echo Test</title>
        <script>
            function init() {
            websocket = new WebSocket("ws://localhost:6060/talk");

            websocket.onopen = function() { document.getElementById("output").innerHTML += "<p>> CONNECTED</p>"; };

            websocket.onmessage = function(evt) { document.getElementById("output").innerHTML += "<p style='color: blue;'>> RECEIVE: " + evt.data + "</p>"; };

            websocket.onerror = function(evt) { document.getElementById("output").innerHTML += "<p style='color: red;'>> ERROR: " + evt.data + "</p>"; };
            }

            function sendMessage(message) {
            document.getElementById("output").innerHTML += "<p>> SEND: " + message + "</p>";

            websocket.send(message);
            }

            window.addEventListener("load", init, false);
        </script>
    </head>
    <body>
        <h2>Welcome %1</h2><small>Refresh browser to clear page and resubscribe</small><br/><br/>
        <input onkeypress="if(this.value) {if (window.event.keyCode == 13) { sendMessage(this.value); this.value = null; }}"/>  
        <div id="output"></div>
    </body>
</html>