-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestClient.html
More file actions
executable file
·35 lines (33 loc) · 1.16 KB
/
testClient.html
File metadata and controls
executable file
·35 lines (33 loc) · 1.16 KB
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
<!DOCTYPE html>
<html>
<head>
<title>WebSocket test</title>
</head>
<body>
<textarea cols="100" rows="10"></textarea>
<br />
<button onclick="send()">Send</button><button onclick="close()">Close</button>
<script>
var ws = new WebSocket("ws://" + window.location.host + ":5678/"),
messages = document.createElement('ul');
ws.onmessage = function (event) {
var messages = document.getElementsByTagName('ul')[0],
message = document.createElement('li'),
content = document.createTextNode(event.data);
message.appendChild(content);
messages.appendChild(message);
};
document.body.appendChild(messages);
ws.onclose = function() {
alert('WebSocket closed');
}
function send() {
var message = document.querySelector('textarea').value;
ws.send(message);
}
function close() {
ws.close();
}
</script>
</body>
</html>