aboutsummaryrefslogtreecommitdiffstats
path: root/examples/websocket/templates/ws.html
blob: 2d38fdfceed3e3f6f75c327d32a01137ad8f469e (plain) (blame)
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
<!doctype html>
<html>
<head>
    <script src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
</head>
<body>
    <input id="msg" type="text"></input>
    <button id="send">
        Send
    </button><BR>
    <textarea id="log" cols=100 rows=50>
    </textarea>
    <script>
var sock = new WebSocket("ws://{{servername}}:40080/ws");

sock.onopen = ()=>{
    console.log('open')
}
sock.onerror = (e)=>{
    console.log('error',e)
}
sock.onclose = ()=>{
    console.log('close')
}
sock.onmessage = (e)=>{
    $("#log").val(
            e.data +"\n" + $("#log").val());
}
$("#msg").keypress(function(e){
    if (e.which == 13)
    {
    sock.send($("#msg").val());
    $("#msg").val("");
    }
});
$("#send").click(()=>{
    sock.send($("#msg").val());
    $("#msg").val("");
});
    </script>
</body>
</html>