-
Notifications
You must be signed in to change notification settings - Fork 0
/
step2.html
33 lines (31 loc) · 994 Bytes
/
step2.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
<!doctype html>
<html lang="de_DE">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Chat</title>
<link rel="stylesheet" href="main.css">
</head>
<body>
<button>Send a message</button>
<ol id="log">
</ol>
<script type="text/javascript">
var conn = new WebSocket('ws://127.0.0.1:8080/chat');
conn.onopen = function(ev) {
conn.send('hi there');
}
conn.onmessage = function(ev) {
let li=document.createElement('li');
li.innerText = ev.data;
document.getElementById('log').append(li);
}
document.querySelector('button').addEventListener('click',function() {
if (conn) {
let date = new Date();
conn.send(date.toLocaleDateString() + ' ' + date.toLocaleTimeString() +' hello');
}
});
</script>
</body>
</html>