Created
March 26, 2012 20:09
-
-
Save TooTallNate/2209310 to your computer and use it in GitHub Desktop.
Running a "full-featured" REPL using a net.Server and net.Socket
This file contains 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 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') | |
} | |
}) |
This file contains 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') | |
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) |
how to start the client and server in this application?
i tried node repl-server.js it is giving me an error
module.js:538
throw err;
^
Error: Cannot find module 'C:\D Drive\Learning\repl-server.js'
at Function.Module._resolveFilename (module.js:536:15)
at Function.Module._load (module.js:466:25)
at Function.Module.runMain (module.js:676:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
req.headers['x-forwarded-for'] it gives local ip address ...
i want remote ip address