Skip to content

Instantly share code, notes, and snippets.

@isaacs
Created February 8, 2010 22:22
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 isaacs/298653 to your computer and use it in GitHub Desktop.
Save isaacs/298653 to your computer and use it in GitHub Desktop.
var tcp = require("tcp"),
http = require("http"),
sys = require("sys");
http.createServer(function (req,res) {
sys.debug("from http server: connect");
res.sendHeader(200, {});
res.sendBody("hi");
for (var i in req.headers) {
res.sendBody("\nHEADER "+i+": "+req.headers[i]+"\n");
}
res.finish();
}).listen(8000);
sys.debug("server started, waiting for connection...");
var conn = tcp.createConnection(8000);
conn.forceClose(); // attach some listeners. There MUST be a better way to do this?
conn.addListener("receive", function (chunk) { sys.error(chunk) });
conn.addListener("close", function () { sys.error("\n\nDONE!\n\n") });
conn.addListener("connect", function () {
sys.debug("connecting...");
conn.send("GET / HTTP/1.1\r\n");
conn.send("X-Multiline: this is part of it\r\n And-so: is this.\r\n" +
"X-Two: 2\r\n\r\n");
});
conn.connect(8000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment