-
Notifications
You must be signed in to change notification settings - Fork 0
/
sockettest.html
34 lines (30 loc) · 885 Bytes
/
sockettest.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<script>
const socket = new WebSocket("ws://localhost:5000/chat");
socket.onopen = function (e) {
console.log("Connection established");
};
socket.onmessage = function (event) {
console.log(`Data received from server: ${event.data}`);
};
socket.onclose = function (event) {
if (event.wasClean) {
console.log(
`Connection closed cleanly, code=${event.code} reason=${event.reason}`
);
} else {
console.log("Connection died");
}
};
socket.onerror = function (error) {
console.log(`[error] ${error.message}`);
};
</script>
</head>
<body></body>
</html>