Last active
February 3, 2019 10:15
-
-
Save vvscode/a87cae1d579bdbcdecb72e5eb68ce298 to your computer and use it in GitHub Desktop.
Websocket shell (node.js)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "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" | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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