-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.html
41 lines (41 loc) · 1.22 KB
/
test.html
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
<!DOCTYPE html>
<html>
<head>
<title>WebSocket Test</title>
</head>
<body>
<label for="chatTXT">Chat:</label>
<input type="text" id="chatTXT" size="64" />
<input type="button" value="send" id="chatBTN"/>
<div id="chat"></div>
<script>
var chat = document.getElementById("chat");
var btn = document.getElementById("chatBTN");
var txt = document.getElementById("chatTXT");
var conn;
btn.onclick = function()
{
conn.send(txt.value);
txt.value = "";
}
if(window["WebSocket"])
{
conn = new WebSocket("ws://{{$}}/ws");
conn.onclose = function(evt)
{
console.log(evt);
chat.innerHTML += "Connection Closed. <br />";
}
conn.onmessage = function(evt)
{
chat.innerHTML += evt.data + '<br />';
}
}
else
{
chat.innerHTML += "No WebSockets";
console.log("No websockets.");
}
</script>
</body>
</html>