読者です 読者をやめる 読者になる 読者になる

#!/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);
});

https://gist.github.com/1947213