-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
37 lines (33 loc) · 1.15 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>WebSocket Client</title>
</head>
<body>
<h1>WebSocket Client</h1>
Open the developer console to see the messages from the WebSocket server.<br>
Change the WebSocket server URL in the script section of the index.html.
<script>
// Create a new WebSocket connection
const socket = new WebSocket('ws://127.0.0.1:8000');
// Connection opened
socket.addEventListener('open', function (event) {
console.log('Connected to WebSocket server');
});
// Listen for messages
socket.addEventListener('message', function (event) {
console.log('Message from server:', event.data);
});
// Connection closed
socket.addEventListener('close', function (event) {
console.log('Disconnected from WebSocket server');
});
// Handle errors
socket.addEventListener('error', function (event) {
console.error('WebSocket error:', event);
});
</script>
</body>
</html>