Skip to content

Instantly share code, notes, and snippets.

@superbrothers
Created March 1, 2012 04:09
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 superbrothers/1947213 to your computer and use it in GitHub Desktop.
Save superbrothers/1947213 to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
/*
* ./wrnet.js www.yahoo.co.jp 80
* > GET / HTTP/1.0
*/
var net = require("net")
, readline = require("readline")
, rl = readline.createInterface(process.stdin, process.stdout)
, argv = process.argv.slice(2);
var client = net.connect(argv[1], argv[0], function () {
rl.prompt();
}).on("data", function (data) {
console.log(data.toString());
}).on("end", function () {
process.exit(0);
});
rl.on("line", function (line) {
try {
client.write(line.trim() + "\r\n");
} catch (e) {
console.log(e);
process.exit(1);
}
}).on("close", function () {
client.end();
process.exit(0);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment