Skip to content

Instantly share code, notes, and snippets.

@vvscode
Last active February 3, 2019 10:15
Show Gist options
  • Select an option

  • Save vvscode/a87cae1d579bdbcdecb72e5eb68ce298 to your computer and use it in GitHub Desktop.

Select an option

Save vvscode/a87cae1d579bdbcdecb72e5eb68ce298 to your computer and use it in GitHub Desktop.
Websocket shell (node.js)
{
"name": "ws-proxy",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"exec": "^0.2.1",
"ws": "^3.2.0"
}
}
const WebSocket = require("ws");
const exec = require("exec");
const PORT = 9876;
const wss = new WebSocket.Server({ port: PORT });
wss.on("connection", ws => {
console.log("New client at ", new Date());
ws.on("message", message => {
console.log("received: %s", message);
exec(message, (err, out, code) => {
console.log(err, out, code);
ws.send(out);
});
});
});
console.log(`Listen to the :${PORT}`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment