-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
35 lines (28 loc) · 792 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
27
28
29
30
31
32
33
34
35
var express = require('express'),
io = require('socket.io'),
fs = require('fs');
var app = express(),
server = require('http').createServer(app),
io = io.listen(server);
app.configure(function() {
// app.use(express.static(__dirname + '/public'));
});
// Server.
app.get('/', function(req, res){
fs.readFile(__dirname + '/public/index.html', function(err, data){
if (err) {
res.writeHead(500);
return res.end('Error loading index.html');
}
res.writeHead(200);
res.end(data);
});
});
server.listen(5000);
// Sockets.
io.sockets.on('connection', function(socket){
// on ball move
socket.on('move', function(data){
io.sockets.emit('move', { x: data.x, y: data.y });
});
});