Skip to content

Instantly share code, notes, and snippets.

@maggocnx
Created July 24, 2013 09:55
Show Gist options
  • Save maggocnx/6069315 to your computer and use it in GitHub Desktop.
Save maggocnx/6069315 to your computer and use it in GitHub Desktop.
server
var express = require("express");
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io').listen(server);
var fs = require('fs');
var printer = require("./printer.js");
app.listen(3000);
var clientSocket;
app.get('/', function (req, res) {
res.sendfile(__dirname + '/index.html');
});
app.use("/public" , express.static( __dirname + '/public'));
app.use(function(req,res,next){
console.log("das passiert immer ");
next();
});
app.get('/test', function (req, res) {
res.writeHead(200,{'Transfer-Encoding':'chunked'});
cnt = 0;
interval = setInterval(function(){
res.write(cnt.toString());
if(cnt++> 10 ){
clearInterval(interval);
res.end("Enn")
}
}, 500);
});
var cnt = 0;
fs.watchFile('testfile', function (curr, prev) {
console.log('the current mtime is: ' + curr.mtime);
console.log('the previous mtime was: ' + prev.mtime);
if(clientSocket)
clientSocket.emit('news', { msg: 'RFiDStart' });
else
console.log("no socket");
});
app.get('/print', function(req, res){
printer.printLines(["BUms", "Hoooo ", "foo"]);
// var buf = new Buffer(1200);
// buf.fill(cnt++);
// fs.writeFile("/dev/backlcd", buf, function(err){
// console.log(err, "err");
res.redirect("/");
// });
});
// io.sockets.on('connection', function (socket) {
// clientSocket = socket;
// // setInterval(function(){
// // socket.emit('news', { hello: 'world' });
// // }, 1000);
// socket.on('my other event', function (data) {
// console.log(data);
// });
// });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment