2010-03-09 07:06:29 +08:00
|
|
|
require("../common");
|
2010-03-19 05:01:17 +08:00
|
|
|
net = require("net");
|
2010-03-20 10:22:04 +08:00
|
|
|
http = require("http");
|
2009-12-05 15:37:46 +08:00
|
|
|
|
|
|
|
var body = "hello world\n";
|
|
|
|
var server_response = "";
|
|
|
|
var client_got_eof = false;
|
|
|
|
|
|
|
|
var server = http.createServer(function (req, res) {
|
2010-02-26 04:54:48 +08:00
|
|
|
res.writeHead(200, {"Content-Type": "text/plain"});
|
2010-04-09 01:44:22 +08:00
|
|
|
res.end(body);
|
2009-12-05 15:37:46 +08:00
|
|
|
})
|
2010-02-27 04:06:32 +08:00
|
|
|
server.listen(PORT);
|
2009-12-05 15:37:46 +08:00
|
|
|
|
2010-03-19 05:01:17 +08:00
|
|
|
var c = net.createConnection(PORT);
|
2009-12-05 15:37:46 +08:00
|
|
|
|
|
|
|
c.setEncoding("utf8");
|
|
|
|
|
|
|
|
c.addListener("connect", function () {
|
2010-02-17 05:15:30 +08:00
|
|
|
c.write( "GET / HTTP/1.0\r\n\r\n" );
|
2009-12-05 15:37:46 +08:00
|
|
|
});
|
|
|
|
|
2010-02-12 16:25:15 +08:00
|
|
|
c.addListener("data", function (chunk) {
|
2009-12-05 15:37:46 +08:00
|
|
|
puts(chunk);
|
|
|
|
server_response += chunk;
|
|
|
|
});
|
|
|
|
|
2010-02-12 16:25:15 +08:00
|
|
|
c.addListener("end", function () {
|
2009-12-05 15:37:46 +08:00
|
|
|
client_got_eof = true;
|
2010-04-09 01:44:22 +08:00
|
|
|
c.end();
|
2009-12-05 15:37:46 +08:00
|
|
|
server.close();
|
|
|
|
});
|
|
|
|
|
|
|
|
process.addListener("exit", function () {
|
|
|
|
var m = server_response.split("\r\n\r\n");
|
|
|
|
assert.equal(m[1], body);
|
|
|
|
assert.equal(true, client_got_eof);
|
|
|
|
});
|