-
Notifications
You must be signed in to change notification settings - Fork 0
/
6.html
39 lines (32 loc) · 943 Bytes
/
6.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
<html>
<body>
<h3>
this is 6 HTML file - with socket.io events
</h3>
<p id="hello">Nothing to see...</p>
<p>
<input id="msgToBroadcast">
<input type="button" id="doBroadcast" value="send">
</p>
<p id="broadcast"></p>
<script src="/socket.io/socket.io.js"></script>
<script>
function hello(msg){
document.getElementById("hello").innerHTML = msg;
};
function broadcast(msg) {
document.getElementById("broadcast").innerHTML = document.getElementById("broadcast").innerHTML + msg + "<br>";
};
var socket = io.connect("/", {
"connect timeout": 3000, "reconnect": false
});
socket.on("hello", hello);
socket.on("broadcast", broadcast);
document.getElementById("doBroadcast").addEventListener("click", function(){
var inp = document.getElementById("msgToBroadcast");
socket.emit("msg", inp.value);
inp.value = "";
});
</script>
</body>
</html>