Created
February 8, 2010 22:22
-
-
Save isaacs/298653 to your computer and use it in GitHub Desktop.
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 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