var child_process = require('child_process');
var ws = require("nodejs-websocket");
console.log("开始建立连接...")
var server = ws.createServer(function(conn){
conn.on("text", function (str) {
var arr=str.split(" ");
var comm=arr.shift();
console.log("收到的信息为:"+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("关闭连接")
});
conn.on("error", function (code, reason) {
console.log("异常关闭")
});
}).listen(8002)
console.log("WebSocket建立完毕")