var child_process = require (' child_process ');
var ws = Require ("Nodejs-websocket");
Console.log ("Start establishing connection ...")
var server = Ws.createserver (function (conn) {
Conn.on ("Text", function (str) {
var arr=str.split ("");
var comm=arr.shift ();
Console.log ("The message Received is:" +str)
Console.log ("******" +comm+ "*******");
var command = comm;
var Argf=arr;
var spawnobj = Child_process.spawn (Comm,arr, {encoding: ' Utf-8 '});
SpawnObj.stdout.on (' Data ', function (chunk) {
Console.log ("PPPP" +chunk.tostring ());
Conn.sendtext (Chunk.tolocalestring ());
});
});
Conn.on ("Close", function (code, reason) {
Console.log ("Close Connection")
});
Conn.on ("Error", function (code, reason) {
Console.log ("Abnormal shutdown")
});
}). Listen (8002)
Console.log ("WebSocket established")
Web socket server code, calling shell exec child_process