Created
October 20, 2021 02:51
-
-
Save TekuConcept/74e45f23662bf56a65acf039c911100b to your computer and use it in GitHub Desktop.
REPL Over Sockets (NodeJS v17.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
var net = require('net') | |
var socket = net.createConnection(5005) | |
socket.on('connect', () => { | |
process.stdin.resume() | |
process.stdin.on('data', d => { | |
socket.write(d) | |
}) | |
}) | |
socket.pipe(process.stdout) | |
socket.on('end', done) | |
socket.on('close', done) | |
function done () { | |
if (done.run) return | |
done.run = true | |
process.stdin.pause() | |
} |
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
var repl = require('repl') | |
var net = require('net') | |
process.stdin.resume() | |
net.createServer(function (socket) { | |
var repls = repl.start({ | |
prompt: "> ", | |
input: socket, | |
output: socket | |
}) | |
// repls.context = bla | |
repls.on && repls.on('exit', () => { | |
console.error('repl exit event, closing socket') | |
socket.end() | |
}) | |
socket.on('error', () => repls.close()) | |
}).listen(5005) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment