-
-
Save richcollins/a8eadd54d1058bcda796 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 http = require("http"); | |
var sys = require("sys"); | |
function sendReq() | |
{ | |
sys.print("sendReq\n"); | |
var resent = false; | |
function resendReq(reason) | |
{ | |
if(!resent) | |
{ | |
sys.print(reason + "\n"); | |
resent = true; | |
sendReq(); | |
} | |
} | |
var client = http.createClient(80, "www.yahoo.com"); | |
client.on("error", function(){ resendReq("client error") }); | |
client.on("close", function(){ resendReq("client close") }); | |
var request = client.request("GET", "/", { Host: "www.yahoo.com" }); | |
request.on("error", function(){ resendReq("request error") }); | |
request.on("close", function(){ resendReq("request close") }); | |
request.end(); | |
var body = ""; | |
request.on("response", function(response){ | |
response.on("error", function(){ resendReq("response error") }); | |
response.on("close", function(){ resendReq("response close") }); | |
response.on("data", function(chunk){ | |
body = body + chunk; | |
}); | |
response.on("end", function(){ resendReq("response end") }); | |
}); | |
} | |
sendReq(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this updated version should work. sendReq was being called twice, once for end and once for close