-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
48 lines (42 loc) · 1.01 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
38
39
40
41
42
43
44
45
46
47
<html>
<head>
<title>
socket test
</title>
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io.connect('http://localhost:5555');
socket.on('server-hello', function (data) {
console.log(data);
addMessage(data.message);
socket.emit('client-hello', { message: 'hello back!' });
});
socket.on('worker-hello', function (data) {
console.log(data);
addMessage(data.message);
});
socket.on('worker-update', function (data) {
console.log(data);
addMessage(data.message);
});
var clientUpdate = setInterval(
function(){
var challenge = Math.random();
socket.emit('client-update', { challenge: challenge });
addMessage('sent challenge: ' + challenge);
}
, 1000
);
function addMessage(msg){
var messages = document.getElementById('messages');
var newP = document.createElement("p");
newP.innerHTML = msg;
messages.insertBefore(newP, messages.firstChild);
}
</script>
</head>
<body>
<div id="messages">
</div>
</body>
</html>