-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.html
More file actions
32 lines (28 loc) · 855 Bytes
/
test.html
File metadata and controls
32 lines (28 loc) · 855 Bytes
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>WebSocket Example</title>
</head>
<body>
<h2>WebSocket Connection</h2>
<button onclick="sendMessage()">Send Message</button>
<p id="status">Connecting...</p>
<script>
const ws = new WebSocket('ws://localhost:8080/websocket'); // Change to your WebSocket server address
ws.onopen = function() {
document.getElementById('status').innerText = 'Connected to WebSocket';
};
ws.onmessage = function(event) {
alert('Message from server: ' + event.data);
};
ws.onclose = function() {
document.getElementById('status').innerText = 'WebSocket Disconnected';
};
function sendMessage() {
ws.send('Hello, Server!');
}
</script>
</body>
</html>