Hi Koichi,

Thanks a lot. After adding Agent, it works.
If no Agent in the option, httpclient would use global agent. And
it wouldn't  re-use this global agent(socket).

Thanks
Herry

On Tue, Jan 31, 2012 at 7:50 AM, Koichi Kobayashi <[email protected]>wrote:

> Hi Herry,
>
> If you need just one connection:
>
>  var myAgent = new http.Agent({maxSockets: 1});
>
>  var req1 = http.get({
>    host: 'example.com',
>    path: '/file1',
>    agent: myAgent
>  }, function(res1) { // (A)
>    res1.on('data', function(chunk) {
>      ...
>    });
>
>    // you should add the 'end' listener
>    // before returning from function (A)
>    res1.on('end', function() { // (B)
>      // you should request before returning from function (B)
>      var req2 = http.get({
>        host: 'example.com',
>        path: '/file2',
>        agent: myAgent
>      }, function(res2) {
>        ...
>      });
>    });
>  });
>
>
>
> On Tue, 31 Jan 2012 14:01:28 +0100, Ben Noordhuis <[email protected]>
> wrote:
>
> > On Tue, Jan 31, 2012 at 03:37, Herry Wang <[email protected]> wrote:
> > > Ben,
> > > Thanks for replying.
> > > I can't understand the timing. You said,
> > > "You need to have the next request queued by the time the response to
> > > the first request finishes. If you don't, the connection to the server
> > > gets closed."
> > >
> > > But in my case, ?the next request only happens right after the first
> > > response.?Like, server responses one string 'ABC', and the client want
> to
>  > > GET abc.html.
> > > In that case, how the next request could be queued ?
> >
> > You can create a custom http.Agent class that keeps the connection
> > open a little longer. Node's default agent closes the connection
> > immediately because it doesn't know if there is going to be a next
> > request.
> >
> > --
> > Job Board: http://jobs.nodejs.org/
> > Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> > You received this message because you are subscribed to the Google
> > Groups "nodejs" group.
> > To post to this group, send email to [email protected]
> > To unsubscribe from this group, send email to
> > [email protected]
> > For more options, visit this group at
> > http://groups.google.com/group/nodejs?hl=en?hl=en
>
>
>
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
>

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to