-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
26 lines (22 loc) · 780 Bytes
/
app.js
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
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
app.get('/', function(req, res){
res.sendfile('index.html');
});
io.on('connection', function(socket){
console.log('A user connected');
setTimeout(function(){
socket.emit('testerEvent', { description: 'A custom event named testerEvent!'});
}, 4000);
//Whenever someone disconnects this piece of code executed
socket.on('disconnect', function () {
console.log('A user disconnected');
});
socket.on('clientEvent', function(data){
console.log(data);
});
});
http.listen(3000, function(){
console.log('listening on *:3000');
});