-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathindex2.html
More file actions
36 lines (36 loc) · 818 Bytes
/
index2.html
File metadata and controls
36 lines (36 loc) · 818 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
33
34
35
36
<!DOCTYPE html>
<html>
<head>
<title>Socket IO example</title>
</head>
<body>
<div id="console"></div>
<script src="/socket.io/socket.io.js"></script>
<script>
let cd = document.getElementById("console");
function ptoc(){
let a = Array.prototype.slice.apply(arguments);
a = a.map(_=>{
if(_ instanceof Object) return JSON.stringify(_);
return _;
})
cd.innerHTML += `<br />${a.join(', ')}`;
console.log(arguments);
}
ptoc("connecting...");
const socket = io({transports:["websocket"]});
socket.on("connect", (data)=>{
ptoc("connected", data);
});
socket.on("disconnect", (data)=>{
ptoc("disconnected", data);
});
socket.on("news", (data)=>{
ptoc("news...", data);
});
socket.emit("ack-message", "hey yo!", function(ackmsg){
console.log("ACK::"+ackmsg);
});
</script>
</body>
</html>