Skip to content

Instantly share code, notes, and snippets.

@mranney
Created March 23, 2010 07:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mranney/340924 to your computer and use it in GitHub Desktop.
Save mranney/340924 to your computer and use it in GitHub Desktop.
example of multi-repl
(in window 1)
rv-mjr2:~$ node repltest.js
node via stdin> foo
'stdin is fun'
(in window 2)
rv-mjr2:~$ telnet localhost 5000
Trying ::1...
Connected to localhost.
Escape character is '^]'.
Hello world
Connection closed by foreign host.
rv-mjr2:~$ telnet localhost 5000
Trying ::1...
Connected to localhost.
Escape character is '^]'.
Hello world
Connection closed by foreign host.
rv-mjr2:~$ socat READLINE UNIX-CONNECT:/tmp/node-repl-sock
node via Unix socket> foo
ReferenceError: foo is not defined
at REPLServer.<anonymous> (eval at <anonymous> (repl:71:28))
at REPLServer.readline (repl:71:19)
at Stream.<anonymous> (repl:32:19)
at IOWatcher.callback (net:338:14)
at node.js:815:9
node via Unix socket> conns
[ { time: Tue, 23 Mar 2010 07:44:14 GMT
, addr: '::1'
, type: 'tcp'
}
, { time: Tue, 23 Mar 2010 07:44:15 GMT
, addr: '::1'
, type: 'tcp'
}
]
node via Unix socket> conns.forEach(function(v,i,a) { self.stream.write(v.time + ":" + v.addr + "\n"); });
Tue Mar 23 2010 00:44:14 GMT-0700 (PDT):::1
Tue Mar 23 2010 00:44:15 GMT-0700 (PDT):::1
(in window 1)
node via stdin> counted connection from: ::1
counted connection from: ::1
node via stdin> conns
[ { time: Tue, 23 Mar 2010 07:44:14 GMT
, addr: '::1'
, type: 'tcp'
}
, { time: Tue, 23 Mar 2010 07:44:15 GMT
, addr: '::1'
, type: 'tcp'
}
]
var sys = require("sys"),
net = require("net"),
repl = require("repl");
conns = [];
message = "Hello world\n";
net.createServer(function (con) {
sys.puts("counted connection from: " + con.remoteAddress);
conns.push({time: new Date(), addr: con.remoteAddress, type: con.type});
con.write(message);
con.close();
}).listen(5000);
repl.start("node via stdin> ").scope.foo = "stdin is fun";
net.createServer(function (socket) {
repl.start("node via Unix socket> ", socket);
}).listen("/tmp/node-repl-sock");
net.createServer(function (socket) {
repl.start("node via TCP socket> ", socket);
}).listen(5001);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment