forked from nkbt/vagrant-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
28 lines (22 loc) · 704 Bytes
/
app.js
File metadata and controls
28 lines (22 loc) · 704 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
var http = require('http');
var fs = require('fs');
var socketIo = require('socket.io');
var server = http.createServer(function handler(req, res) {
fs.readFile(__dirname + '/index.html',
function (err, data) {
if (err) {
res.writeHead(500);
return res.end('Error loading index.html');
}
res.writeHead(200);
return res.end(data);
});
});
server.listen(3000);
var io = socketIo.listen(server);
io.sockets.on('connection', function (socket) {
socket.emit('ping', (new Date()).toJSON());
socket.on('get-ping', function(message) {
socket.emit('ping', (new Date()).toJSON());
})
});