var
io = require(
'socket.io'
);
var
server = require(
'http'
).createServer(serverHandler)
, filesystem = require(
'fs'
)
, cmd = require(
'child_process'
)
, io = io.listen(server);
server.listen(serverPort(80));
function
serverPort(portNumber)
{
console.log(
"Server is running, Port : "
+ portNumber);
return
portNumber;
}
function
serverHandler(request, result)
{
filesystem.readFile(__dirname +
'/index.html'
,
function
(error, data)
{
if
(error)
{
result.writeHead(500);
return
result.end(
'Error loading index.html'
);
}
result.writeHead(200);
result.end(data);
}
);
}
io.sockets.on(
'connection'
,
function
(socket)
{
socket.on(
'execute'
,
function
(data)
{
var
name;
var
value;
for
(index
in
data)
{
name = index;
value = data[index];
}
packetHandler[value]();
});
});
var
packetHandler =
{
'calc on'
:
function
() { cmd.exec(
'calc'
); },
'calc off'
:
function
() { cmd.exec(
'taskkill /f /im calc.exe'
); },
}