Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var port = 8000;
- var WebSocketServer = require('websocket').server;
- var http = require('http');
- var exec = require('child_process').exec
- var child;
- function createGrowlNotification(cmd){
- child = exec('growlnotify -m "'+cmd.body+'" -t "'+cmd.title+'" --image "'+cmd.icon+'"',
- function (error, stdout, stderr) {
- });
- }
- // the main server
- var server = http.createServer(function(request, response) {
- console.log((new Date()) + " Received request for " + request.url);
- response.writeHead(404);
- response.end();
- });
- server.listen(port, function() {
- console.log((new Date()) + " Server is listening on port "+port);
- });
- wsServer = new WebSocketServer({
- httpServer: server,
- autoAcceptConnections: true
- });
- wsServer.on('connect', function(connection) {
- console.log((new Date()) + " Connection accepted.");
- connection.on('message', function(message) {
- if (message.type === 'utf8') {
- console.log("Received Message: " + message.utf8Data);
- createGrowlNotification(JSON.parse(message.utf8Data))
- connection.sendUTF("growlnotify cmd executed");
- }
- else if (message.type === 'binary') {
- console.log("Received Binary Message of " + message.binaryData.length + " bytes");
- connection.sendBytes(message.binaryData);
- }
- });
- connection.on('close', function(connection) {
- console.log((new Date()) + " Peer " + connection.remoteAddress + " disconnected.");
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment