Skip to content

Instantly share code, notes, and snippets.

@itayw
Forked from TooTallNate/repl-client.js
Created November 26, 2013 11:19
Show Gist options
  • Save itayw/7656798 to your computer and use it in GitHub Desktop.
Save itayw/7656798 to your computer and use it in GitHub Desktop.
var net = require('net')
var sock = net.connect(1337)
process.stdin.pipe(sock)
sock.pipe(process.stdout)
sock.on('connect', function () {
process.stdin.resume();
process.stdin.setRawMode(true)
})
sock.on('close', function done () {
process.stdin.setRawMode(false)
process.stdin.pause()
sock.removeListener('close', done)
})
process.stdin.on('end', function () {
sock.destroy()
console.log()
})
process.stdin.on('data', function (b) {
if (b.length === 1 && b[0] === 4) {
process.stdin.emit('end')
}
})
var repl = require('repl')
var net = require('net')
net.createServer(function (socket) {
var r = repl.start({
prompt: 'socket '+socket.remoteAddress+':'+socket.remotePort+'> '
, input: socket
, output: socket
, terminal: true
, useGlobal: false
})
r.on('exit', function () {
socket.end()
})
r.context.socket = socket
}).listen(1337)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment