-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
53 lines (47 loc) · 1.29 KB
/
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//Node Server File
//Creates the server and listens for socket requests from the client.
var express = require('express');
var http = http = require('http');
var io = require('socket.io');
var sys = require('sys');
var exec = require('child_process').exec;
var path = require('path');
var app = express();
app.configure(function(){
app.set('port', process.env.PORT || 8080);
});
app.get('/', function (request, result) {
result.sendfile(__dirname + '/index.html');
app.use(express.static(path.join(__dirname, 'public')));
});
function puts(error, stdout, stderr) {
sys.print(stdout);
sys.print(stderr);
if(error !== null) {
console.log(error);
}
}
function moveLeft() {
exec("/usr/bin/python stepper-left.py", puts);
console.log("Moved left!");
}
function moveRight() {
exec("/usr/bin/python stepper-right.py", puts);
console.log("Moved right!");
}
var server = http.createServer(app).listen(app.get('port'), function(){
console.log("Express server listening on port " + app.get('port'));
});
var io = io.listen(server, {
log: false
});
io.sockets.on('connection', function (socket) {
socket.on('moveLeft', function (data) {
moveLeft();
socket.broadcast.emit('moveLeft', {});
});
socket.on('moveRight', function (data) {
moveRight();
socket.broadcast.emit('moveRight', {});
});
});