aboutsummaryrefslogtreecommitdiffstats
path: root/examples/websocket/templates/ws.html
diff options
context:
space:
mode:
Diffstat (limited to 'examples/websocket/templates/ws.html')
-rw-r--r--examples/websocket/templates/ws.html42
1 files changed, 42 insertions, 0 deletions
diff --git a/examples/websocket/templates/ws.html b/examples/websocket/templates/ws.html
new file mode 100644
index 0000000..2d38fdf
--- /dev/null
+++ b/examples/websocket/templates/ws.html
@@ -0,0 +1,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>