-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.js
More file actions
28 lines (24 loc) · 696 Bytes
/
Copy pathserver.js
File metadata and controls
28 lines (24 loc) · 696 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
var app = require('http').createServer(handler)
, io = require('socket.io').listen(app)
, url = require("url")
, fs = require('fs')
, packetizer = require('./network/three-packets.js');
app.listen(4000);
function handler (req, res) {
var pathname = url.parse(req.url).pathname;
fs.readFile(__dirname + pathname,
function (err, data) {
if (err) {
res.writeHead(500);
return res.end('Error loading file (Doesnt exist on server)');
}
res.writeHead(200);
res.end(data);
});
}
io.sockets.on('connection', function (socket) {
socket.emit('init', { hello: 'world' });
socket.on('move',function(data){
socket.broadcast.emit('move', data);
})
});