-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.html
52 lines (37 loc) · 950 Bytes
/
client.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
42
43
44
45
46
47
48
49
50
51
52
<!doctype html>
<html>
<head>
<title>Test Websocket connection</title>
</head>
<body>
<span>Test Websocket connection</span>
<ul>
<li><button id="closebtn">Close Conn</button></li>
<li><button id="sendbtn">Send Data</button></li>
</ul>
<script>
var ws = new WebSocket('ws://127.0.0.1:1201');
document.getElementById("closebtn").addEventListener('click', ev => {
ws.close();
});
document.getElementById("sendbtn").addEventListener('click', ev => {
ws.send("Potato")
});
ws.onopen = function () {
ws.send("My test message")
};
ws.onclose = function (evt) {
console.log("Connection closed");
ws = null;
}
// Log errors
ws.onerror = function (error) {
console.log('WebSocket Error ' + error);
};
// Log messages from the server
ws.onmessage = function (e) {
console.log(e.data);
};
</script>
</body>
</html>